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

KV caching does not appear to work #36

Closed
qbunt opened this issue Jan 19, 2022 · 4 comments
Closed

KV caching does not appear to work #36

qbunt opened this issue Jan 19, 2022 · 4 comments

Comments

@qbunt
Copy link

qbunt commented Jan 19, 2022

hey @codewithkristian and team! Looks like the KVCache mechanism isn't working as described (or at least I'm not able to use it with the docs provided). I've set the ID properly and I can confirm I'm setting values with that ID via Wrangler, but when I run it in a worker, nothing ever shows up in the KV cache storage.

Is there a specific ttl header I need to set when I'm hitting this server to get the content cached? It's not easy to debug and I'm unclear how I can see what's happening inside kv-cache.js when the worker is running. Thanks in advance!

@devinellis
Copy link

In my case, I wonder if its because I am attempting to cache POST requests to a RESTDataSource?

@qbunt
Copy link
Author

qbunt commented Mar 2, 2022

@devinellis I'm doing a get, but I think I've set all the required variables in the readme, but I also don't know of a way I can debug it easily without pushing it out first

@qbunt
Copy link
Author

qbunt commented Mar 4, 2022

I've got a little more information about this bug. Cache is being read but never written.

image

According to this the interface is super simple to implement, and I believe it's connected correctly. Seems possible I need to pass something in the request header to get caching to write correctly or something, but I cannot figure out where

@qbunt
Copy link
Author

qbunt commented Mar 4, 2022

welp, nevermind @devinellis. Looking through this, apollo will cache based up the RESTDataSource response Cache-Control headers. In our case, not in a position to request that those change, so you can enforce it inside the resolvers.js file like this:

this.get('/v1/user', null, { cacheOptions: { ttl: 60 } })

We're setting these via environment variables, but it may be worth a callout in the docs here, I was completely unaware that the RESTDataSource acted like this.

@qbunt qbunt closed this as completed Mar 4, 2022
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