Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Linode API GET calls #113

Closed
wants to merge 1 commit into from
Closed

Cache Linode API GET calls #113

wants to merge 1 commit into from

Conversation

mhmxs
Copy link
Contributor

@mhmxs mhmxs commented Feb 13, 2024

This change introduces a caching layer in front of the Linode client.

Fixes: #92

@mhmxs mhmxs force-pushed the cache-linode-client branch from 18ed216 to 114d9ad Compare February 13, 2024 14:56
@mhmxs mhmxs added dependencies Pull requests that update a dependency file go Pull requests that update Go code labels Feb 13, 2024
@mhmxs mhmxs force-pushed the cache-linode-client branch from 4b262c2 to 7265b5b Compare February 14, 2024 07:40
@mhmxs mhmxs requested a review from AshleyDumaine February 14, 2024 07:49
@@ -5,6 +5,7 @@ go 1.21
toolchain go1.21.5

require (
github.com/bxcodec/httpcache v1.0.0-beta.3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a concern or not, but just noticed this package(and assuming the gotcha package as well) have been on the same beta version for over 3 years at this point with no updates, are we ok with adopting these dependencies? if we want to accept them I could buy into that, just want to make sure we are aware of them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ETag caching here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eljohnson92 Other libraries (what i found) are archived, so i found this one a better option than writing our own.
I'm open to use something else, do you have any preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srust Maybe i'm wrong, but Linode API doesn't send ETag header, at least the for web ui. Could you please clarify your suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhmxs as an alternative to this, could we perhaps use a more general purpose go caching library to store cache instead of the purpose-built http caching library? I would be open to using this if we thing it would be the best option, just want to explore some alternatives as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eljohnson92 This was the simplest to implement. The alternatives i found:

  • stores string or []byte, so we have to serialize data
  • stores any or interface{}, so we have to type enforce type after every get
  • needs an extra layer between business logic and Llinode client
  • already archived
  • not designed for high concurrency
  • doesn't support TTL

So i'm glad to use another library, if you have better option. This library was the best result of my researching :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bummer about ETag - oh well.

)

var (
initClient sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to limit us to using one API client (and thus one access token) for all CAPL-managed clusters. Is there another way to have both caching for the API while supporting something like per-cluster Linode tokens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbzzz we had one access token before this change, and unnecessary client creations (access token never changes). So i think my version is better than the previous one (more configurable, and less footprint). But your point is also valid, it needs a new concept how to define per-cluster Linode token. Once we change to per-cluster, this cache solution won't be the best for us. So this is an interesting question.

@mhmxs
Copy link
Contributor Author

mhmxs commented Mar 2, 2024

The upcoming change invalidates this one: #142

@mhmxs mhmxs closed this Mar 2, 2024
@mhmxs mhmxs deleted the cache-linode-client branch March 2, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache Linode API calls
5 participants