Comments (6)
Thanks @JakeCoxon that’s a good question! Yeah currently that’s the only way, because it might be dangerous to clear a cached key automatically: we don’t know if there’s any existing component still reading from that key.
To support that, we need to maintain a list for active keys (add/remove a key to the list when the SWR’s parent component is mounting/unmounted), which is not yet implemented.
Finally, we plan to export the cache APIs from the lib, and add options to the config soon. So you can override it with your own implementation like LRU cache, or just manipulate the cache object.
from swr.
Finally, we plan to export the cache APIs from the lib, and add options to the config soon. So you can override it with your own implementation like LRU cache, or just manipulate the cache object.
that sounds great!
from swr.
SWR 1.0 has a new feature that can create custom cache provider to apply your own logic of managing cache. But as @shuding 's the comment above, this is still pretty dangerous to do which could lead to inconsistence between UI and cache state.
from swr.
I think a middleware and ref counting (#92) can work. I can build a prototype for this.
from swr.
This middleware should work, maybe I can publish it as a package:
https://gist.github.com/shuding/915d6844db74e131ece951a2eff0f320
from swr.
@shuding The counter middleware removes key from cache, however the values corresponding to errorKey
and isValidatingKey
are still kept.
from swr.
Related Issues (20)
- Type error when overriding global fetcher function with null HOT 3
- SWR mutate does not trigger even if I have a hook mounted with the same key HOT 1
- fallback doesn't work with `useSWRInfinite` and next app router HOT 1
- Type error when fallback option with undefined.
- Repeat render
- useSWRMutation - Type error: Expected 2-3 arguments, but got 1. HOT 1
- Cannot read properties of null (reading 'useSyncExternalStore') HOT 1
- Optimistic update with useSWRMutation HOT 2
- typescript is incorrect when using different fetchers but the same key HOT 3
- Type safe Key as Url for the SWR fetcher
- Unexpected `revalidateIfStale = false` initial load behavior on key change HOT 1
- useSWR('key', fetcher) calls fetcher non-deterministically even when `key` is in the fallback
- Can I call both of onSuccess function in trigger options and useSWRMutation options?
- Fetcher isn't run again when error boundary resets using Suspense. HOT 1
- SWR should assert the data not be undefined if `isLoading` is false and `error` is null HOT 1
- Clarification Needed on Handling data for Optimistic Updates in useSWRMutation
- swr repeated render problem
- "isLoading" always true after clear the cache HOT 1
- Missing export of type `SWRInfiniteMutatorOptions` starting from 2.2.5 HOT 1
- Cache flaw: mutate of cache keys is ignored when no consuming hook is mounted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swr.