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

Discussion: why have an client side API cache? #373

Closed
nicolai86 opened this issue Jun 25, 2016 · 2 comments
Closed

Discussion: why have an client side API cache? #373

nicolai86 opened this issue Jun 25, 2016 · 2 comments

Comments

@nicolai86
Copy link
Contributor

I'm wondering why the API SDK has a local cache? Assuming you're already caching on the server side the client cache probably doesn't add a lot of benefit but some maintenance burden.

Removing the cache would simplify the API SDK a little, and also remove one possible point for errors (less caches = less stale results)

@moul
Copy link
Contributor

moul commented Jun 27, 2016

The cache is used to avoid listing resources each time we need to get a resourced based on something else than its ID, for example querying a server based on its hostname

$ scw _flush-cache >/dev/null
$ time scw --debug inspect --format '{{ .Hostname }}' server:swarm-node-1

DEBU[0000] Filling the cache
DEBU[0000] curl -X GET -H "Content-Type: application/json" -H "User-Agent: scw/v1.9.0+dev" -H "X-Auth-Token: 00000000-0000-1000-0000-000000000000" https://api.scaleway.com/servers
DEBU[0001] curl -X GET -H "Content-Type: application/json" -H "User-Agent: scw/v1.9.0+dev" -H "X-Auth-Token: 00000000-0000-1000-0000-000000000000" https://api.scaleway.com/servers/22baa68d-e439-48d1-9437-b1a764f34acc
swarm-node-1

0.11s user 0.03s system 8% cpu 1.821 total
$ time scw --debug inspect --format '{{ .Hostname }}' server:swarm-node-1

DEBU[0000] curl -X GET -H "Content-Type: application/json" -H "User-Agent: scw/v1.9.0+dev" -H "X-Auth-Token: 00000000-0000-1000-0000-000000000000" https://api.scaleway.com/servers/22baa68d-e439-48d1-9437-b1a764f34acc
swarm-node-1

0.12s user 0.02s system 29% cpu 0.460 total
  • First call: 1.8sec
    • listing all servers
    • inspecting the one matching the hostname
  • Second call: 0.5sec
    • inspecting the server matching the hostname in the cache

When you create a server with a named bootscript, a named image, a raw ip address and secondary volumes, you can quickly gain several seconds

It is also used by the autocomplete scripts of the CLI that will only look in this cache file to avoid querying the API just for autocomplete


As you did in #369, I'm fully 👍 to keep this feature in the CLI, but make it optional when using the API sdk

Looks good to you ?

@nicolai86
Copy link
Contributor Author

@moul thanks for explaining! I fully understand the use case for the CLI. I'll check if there's a nice way to migrate the caching for cli only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants