Different TTL for queries and objects in the cache
Hi guys! Thank you very much for the opportunity to use this library. I would be very grateful if you could help me with the following problem :)
Minimum context:
I want to use the following invalidationPolicy configuration settings:
invalidationPolicies: {
timeToLive: 15 * 60 * 1000, // 15 minutes in milliseconds
types: {
User: {
timeToLive: 60 * 1000, // 1 minute in milliseconds
},
},
}
It turns out that queries inside ROOT_QUERY will live for 15 minutes. And the cached objects themselves will live for one minute.
Problem description (page and query names are used as an example only):
-
I go to the
/userpage, which uses the getUser query. When it is executed, the query itself (i.e. getUser) and the response of this query (i.e. the User object itself) are cached. -
Then I wait one minute for the User object in the cache to become invalid (i.e. the TTL has expired). It is worth noting that the getUser query is still valid.
-
I go to the page
/. At this point, the getUser query remains in the cache inside ROOT_QUERY, but the cached User object is not there (it was deleted because it was invalid). -
I go back to the page
/userwithin 15 minutes. And now I have no data on the page, because the ROOT_QUERY still contains broken links to objects in the cache, which are no longer in this cache!
Expected behavior:
First, I would like to clarify whether this behavior is expected? If yes, what would you recommend me to avoid this behavior. If not, what option is better to use:
- Check object references in ROOT_QUERY for null / undefined? (but as I understand - you need to go to Apollo Client with this question)
- Delete query objects (or reference objects themselves) when deleting entities whose TTL has expired?