puck icon indicating copy to clipboard operation
puck copied to clipboard

Add cache invalidation options to external field

Open FedericoBonel opened this issue 2 months ago • 1 comments

Description

Currently, there is no way to invalidate the internal cache that external fields use for fetching their lists. This leads to outdated data when the listed content is frequently updated, requiring a page refresh to get the latest data or disabling the cache all together.

If Puck could provide a way to manage that internal cache so developers can control when it should be invalidated and refetched, it would avoid this issue and make external fields suitable for more use cases.

Considerations

Proposals

Proposal 1

  • Provide options to set the time the cache should be reused in milliseconds. This would prevent the cache from becoming outdated during long editing sessions.
fields: {
  myField: { 
    type: "external", 
    cache: { 
      time: 60000 // set a cache lifetime of 1 minute, defaults to infinite
    },
  },
}

Proposal 2

  • Provide a function that returns the cache key to use internally for the current query and filters. This would allow more control over which cached data is used and when.
fields: {
  myField: { 
    type: "external", 
    cache: {
      getKey: ({ id, query, filters }) => `${id}-${query}-${JSON.stringify(filters)}`, // Or null to disable the cache
    }
  },
}

It could also be combined with Proposal 1.

FedericoBonel avatar Oct 07 '25 07:10 FedericoBonel

This is a follow up to #1339 which added options to disable the cache

FedericoBonel avatar Oct 07 '25 07:10 FedericoBonel