-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove old cached items #4
Comments
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. |
that sounds great! |
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. |
I think a middleware and ref counting (#92) can work. I can build a prototype for this. |
This middleware should work, maybe I can publish it as a package: https://gist.github.com/shuding/915d6844db74e131ece951a2eff0f320 |
@shuding The counter middleware removes key from cache, however the values corresponding to |
Hi great library. Is there any way to delete old cache items to avoid using up lots of memory? For example in an app with lots of pages where you want to cache if the user presses back but they are unlikely to go back more than 10. Perhaps this could be written in user space by using
mutate(key, null)
?The text was updated successfully, but these errors were encountered: