Replies: 4 comments 5 replies
-
Another issue I might face is that I have an endpoint that returns a random image. So if I query randomImage ten times then the cache might hold onto 10 Image objects in the cache so it would also be nice to have them expire after a few minutes as well |
Beta Was this translation helpful? Give feedback.
-
Hiya 👋 Happy to hear you're interested in using Graphcache's offline support! But we did think about this problem in particular and have an alternative solution. We have an exchange that alters when operations are refetches from the API based on an in-memory timestamp per query: https://formidable.com/open-source/urql/docs/api/request-policy-exchange/ This solves the issue elegantly while keeping the extra code and stored timestamps to a minimum. This works nicely because our "request policies" are a separate piece of logic for which the exchanges (specifically the caches) determine what to do on a match or mismatch. It doesn't persist the timestamp though, which would be easy to add, but we chose not to since it's still a good idea to use
To address this separately, this shouldn't be an issue. Graphcache garbage collects unreachable entities, so everything that's been fetched from your API but isn't referenced anymore is deleted. |
Beta Was this translation helpful? Give feedback.
-
Hey! Thank's for the response! I didn't see the request-policy-exchange plugin before. It looks exactly like what I need but at the same time it looks like the TTL is global. However generally the expiry time for my items are variable based on what they are. Is there a way to specify a TTL for each query? I don't see that option in the docs. Great to hear that the cache is auto-cleared as well |
Beta Was this translation helpful? Give feedback.
-
Hmmm Ive been benchmarking both Apollo Client and URQL because when opening a new tab performance really matters and I've noticed that URQL is slower than Apollo even tho its smaller. To benchmark I:
URQL was around 300ms and Apollo was on 250ms |
Beta Was this translation helpful? Give feedback.
-
Hello!
I'm working on a new tab page extension for chrome so my react app is opened and closed multiple times in short bursts. I am looking into storing the cache into localStorage and rehydrating it. This seems easily doable with the offline support of GraphCache. What I'm wondering is if it was possible to tell the cache for a query to expire after a few minutes. For example I don't want the user information to be fetched every time a new tab is opened but rather once every minute. Is this something doable? I can't seem to find anything in the docs but I may be looking in the wrong place
Beta Was this translation helpful? Give feedback.
All reactions