Coder Social home page Coder Social logo

Remove old cached items about swr HOT 6 CLOSED

JakeCoxon avatar JakeCoxon commented on May 14, 2024 2
Remove old cached items

from swr.

Comments (6)

shuding avatar shuding commented on May 14, 2024 3

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.

hems avatar hems commented on May 14, 2024

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.

huozhi avatar huozhi commented on May 14, 2024

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.

shuding avatar shuding commented on May 14, 2024

I think a middleware and ref counting (#92) can work. I can build a prototype for this.

from swr.

shuding avatar shuding commented on May 14, 2024

This middleware should work, maybe I can publish it as a package:

https://gist.github.com/shuding/915d6844db74e131ece951a2eff0f320

from swr.

piotr-cz avatar piotr-cz commented on May 14, 2024

@shuding The counter middleware removes key from cache, however the values corresponding to errorKey and isValidatingKey are still kept.

from swr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.