apollo-feature-requests
apollo-feature-requests copied to clipboard
Add Expiration / TTL to InMemoryCache
We are using ApolloClient + InMemoryCache to do some GraphQL queries. However, our backend data is not immutable, and therefore, we might need to get the fresh data every some time. It looks like the current InMemoryCache does not have a way to set the TTL to cached data, and the data will stay there for a long time, if not kicked out by size limit.
I would like to suggest to add a feature in InMemoryCache to limit the Time-to-live in InMemoryCache, which can be implemented in either an eager or lazy way.
Product Questions to consider
- TTL means in a normalized cache each field can potentially have different TTL values. would the approach follow a pattern such as:
- TTL per-field
- TTL per-query
- TTL per-object
- TTL per something else?
-
Is the TTL client or server controlled?
-
Would we apply this to all 3 clients?
- iOS
- Kotlin
- Web Client?
@Sumu-Ning Thanks for reporting this, we'll consider it and keep this FR open for others in the community to share their thoughts. I also added some product considerations we'd be making in implementing something such as this.
Has there been any progress on adding TTL configuration for apollo client cache? It would be nice to have this fine grained control over cache expiration. Thanks!
@torressam333 no updates to share at the moment 🙂. We are aware of the growing popularity of this request but we haven't yet prioritized it on our roadmap. We'll update this request when we know more.
@jerelmiller Sounds good.
Is the recommended approach for custom cache management to use eviction/gc for the time being?
https://www.apollographql.com/docs/react/caching/garbage-collection
Thanks!
@torressam333 yep that should work for you 🙂