Replies: 9 comments 37 replies
-
Possible to add an invalidate function to the cache? The implementation I use is: function invalidate<TParams extends any[], TValue>(
cache: Cache<TParams, TValue>,
...args: TParams
) {
cache.evict(...args);
cache.prefetch(...args);
} |
Beta Was this translation helpful? Give feedback.
-
Is it possible to notify subscribers when an eviction happens? Currently no notification is given, unless its an evictAll i believe. similarly, evicting and forcing an update afterwards does not cause the suspense fallback to show. Intended? You can see it in the app above by going to the posts, and clicking evict current page |
Beta Was this translation helpful? Give feedback.
-
The current eviction policy seems unpredictable and aggressive, sometimes causing surprising evictions. In the app above, if you go to the posts, you'll see that sometimes when pressing the next button, a complete cache blowout has occurred forcing a suspense fallback. Will also notice it in the users demo (loading a new user will sometimes show all other previously loaded users are now evicted). I was thinking a possible strategy is to allow the user to provide their own implementation of the internal cacher so to leave the eviction policy to them. I would personally want to use a LRU cache, but some might consider another type of cache. Providing the inversion of control could satisfy all use cases. What do you think? |
Beta Was this translation helpful? Give feedback.
-
I commonly want to know if the current cache item is revalidating (no suspense fallback). What do you think about an API like this: const [value, revalidating] = Cache.read() my current implementation for this is using this helper function: function useRead<TParams extends any[], TValue>(
cache: Cache<TParams, TValue>,
...args: TParams
) {
const value = cache.read(...args);
const status = useCacheStatus(cache, ...args);
return [value, status === 'pending'] as const;
} which seems to work |
Beta Was this translation helpful? Give feedback.
-
provide built in hooks? this one is not really a big deal and philosophically i can understand it not being part of the cache. But something like |
Beta Was this translation helpful? Give feedback.
-
the current getValueIfCached throws an error if rejected, which makes it cumbersome in some cases. Thoughts on providing a |
Beta Was this translation helpful? Give feedback.
-
the |
Beta Was this translation helpful? Give feedback.
-
the type inference feels lacking, I think the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Here's a little app i made for demonstrative purposes: stackblitz.com/edit/vitejs-vite-v6umf3?file=src/App.tsx
After using this library for a couple days, I've gathered some feedback:
Will make a comment for each
Beta Was this translation helpful? Give feedback.
All reactions