apollo-cache-policies: Find cache entries with expired TTL?
Hi @danReynolds,
Thanks for your work on this library, it looks great! I’m currently experimenting with Apollo Client 3.0 and was wondering if apollo-invalidation-policies might be suitable for my use case.
TL;DR I’m trying to find entries of a certain type in my cache that haven’t been queried in over a week, and evict them.
Long story:
I’m building a React Native app, using apollo-cache-persist to save the cache on the device and persist between sessions. I’m trying to stop the size of the cache growing forever by evicting certain parts of it based on some conditions.
For example, I fetch an Article from my CMS which gets stored in the cache. I’d like this particular Article to be evicted from the cache if it hasn’t been queried in over a week. My initial thought was that I could add a queriedAt local-only field to Article. Each time an Article is fetched (from the CMS or from the cache), the queriedAt field would update to a timestamp of now. Then each time the app launches, I would query any Articles with a queriedAt date greater than 1 week ago, and cache.evict() them.
My understanding of this library is that timeToLive will evict an entry from the cache after the defined time period, but only when that entry is queried? Is there a way to automatically evict all the entries with an expired timeToLive? And, in my case, reset the timeToLive each time the entry is queried?
Thanks so much!
Ed
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
Hey @edxv ! Thanks for following up, I’ll take a quick pass at doing it today, I think it might be pretty quick actually. Otherwise I’ll let you know and would welcome contributions!