apollo-cache-policies icon indicating copy to clipboard operation
apollo-cache-policies copied to clipboard

`cacheTime` inconsistently set for existing queries

Open dlehmhus opened this issue 10 months ago • 2 comments

Bug: Inconsistent cacheTime updates in EntityTypeMap.write method

Description

The write method in EntityTypeMap.js inconsistently handles the cacheTime property when updating entities. While new entities correctly receive a cacheTime, updates to existing entities or their fields do not update the timestamp. This leads to incorrect cache invalidation behavior since the cache policy relies on cacheTime to determine staleness.

Current Behavior

  • New entities receive a cacheTime stamp
  • Updates to existing query field entries do not update cacheTime
  • New field entries in existing entities do not receive a cacheTime

For example, the entry for "bar" never expires for the following data, since it doesn't contain a cacheTime.

{
   "ROOT_QUERY.configurationByCanonical":{
      "dataId":"ROOT_QUERY",
      "typename":"Query",
      "fieldName":"configurationByCanonical",
      "storeFieldNames":{
         "__size":2,
         "entries":{
            "configurationByCanonical("{ "canonical":"foo" }")":{
               "variables":"undefined",
               "args":"undefined"
               "cacheTime": 1739268658057
            },
            "configurationByCanonical("{  "canonical":"bar" }")":{
               "variables":"undefined",
               "args":"undefined"
            },
         }
}

Expected Behavior

Every write operation should update the cacheTime to ensure accurate cache invalidation:

  • New entities should receive a cacheTime (currently working)
  • Updates to existing query field entries should update cacheTime
  • New field entries in existing entities should receive a cacheTime

Impact

This bug can cause cache entries to remain stale longer than intended (indefinitely), as the invalidation policy cannot accurately determine when the data was last updated.

dlehmhus avatar Feb 11 '25 10:02 dlehmhus