Skip to content
Source
Sign inSign up
TanStack/query

expose custom cache #4687

Send to my agent
ClosedTkDodo opened this issue 0 comments
TkDodocommented

context

Inspired by swr cache provider, we can allow to pass a "custom cache" into our QueryCache:

new QueryClient({
  queryCache: new QueryCache({
    cache: myCache
  })
})

The cache would have to adhere to a map-like interface, and we should probably re-write our internal object to a standard Map.

This would allow features like:

  • limit cache size (as discussed here)
    • you could evict unused cache entries by other criteria than being time-based
  • persist to local storage on a per-query basis
    • limitation: writes could be async, but reads would need to be sync
  • reset cache between test runs (we can already do that in different ways though)
  • other use-cases I haven't thought of?

proposal

  • re-write internal cache object to a Map
  • allow custom caches to be passed in that adhere to a map-like interface
  1. TkDodo added labelsv5

  2. TkDodo assignedTkDodo

  3. TkDodo closed this

Sign in to join this conversation.