GithubHelp home page GithubHelp logo

Comments (10)

BryanDonovan avatar BryanDonovan commented on August 16, 2024 1

Hmm. I see the benefits of your proposed solution, but I'm not seeing an easy solution that fits all scenarios.

The original intent of the multi-cache, if used with a memory cache, is to have a very short TTL for the memory cache compared to the lower cache. E.g, you would perhaps only want to cache data in memory with a TTL of 5 minutes with a redis backend that has a TTL of 24 hours.

I don't think most people would have the higher level cache have a similar TTL as the lower level cache, and therefore wouldn't want the higher cache to receive the remaining TTL from the lower cache.

Providing options that allow this to be configurable seems like it would be pretty confusing. I'm open to ideas though.

from cache-manager.

vmattila avatar vmattila commented on August 16, 2024 1

I am bumbing up this issue/question as struggling also with some inconsistency in multi_caching policies.

In my opinion, TTL values should always be considered as maximum time an entry is kept in cache. Store implementations can always purge the cache entry before TTL but "never" after. Thus, higher level caches should always have lower TTL than lower level level caches. For me, it makes no sense to have TTL of 10 sec in memory but 5 sec in redis.

TTLs per item are indeed tricky. Again, in my personal opinion, if default TTL for a store is lower than item TTL, the store TTL should be used. For example, if I have cache layers memory (10 sec TTL) and redis (60 sec TTL), and then set item with TTL 30 sec; memory layer should have it for 10 sec and redis for 30 sec.

I did also notice that https://github.com/theogravity/node-cache-manager-memory-store does not implement TTL at all, so all cache items would be kept in cache forever, won't they? This might be worth another issue & PR though. ;)

from cache-manager.

BryanDonovan avatar BryanDonovan commented on August 16, 2024

Thanks @dcolens. Do you want to try implementing this? Otherwise I can try when I have time, but it might be a week or so.

from cache-manager.

astanciu avatar astanciu commented on August 16, 2024

Any updates on this? Seems like a pretty big problem for multi-caching...

from cache-manager.

BryanDonovan avatar BryanDonovan commented on August 16, 2024

Sorry, I didn't hear back from you.. I was wondering if you wanted to try implementing the solution. I'm pretty busy these days but will get to it eventually.

from cache-manager.

dcolens avatar dcolens commented on August 16, 2024

I don't have time right now for implementing, I found the issue while experimenting with multi-caching, I like the concept a lot!

from cache-manager.

BryanDonovan avatar BryanDonovan commented on August 16, 2024

I'm not sure how feasible this is. The problem I see is that you don't necessarily know the TTL of the entry from the lower cache, so you can't be sure to pass it up to the higher cache.

I might be missing something, but it seems like the worst case scenario is a rare cache miss.. correct me if I'm wrong though.

from cache-manager.

dcolens avatar dcolens commented on August 16, 2024

In the scenario where multiple servers are used for load balancing it will cause cache inconsistency. For example: serverA caches entryA, serverB gets a query for entryA it finds it in the lower level cache and caches it in the mem cache, now entryA will still be present in serverB while it already expired in serverA.

In my use case, this made the functionality unusable. So yes, in my opinion the lower level caches should return the remaining TTL when queried in a multi-cache scenario.

from cache-manager.

websocket98765 avatar websocket98765 commented on August 16, 2024

I did also notice that https://github.com/theogravity/node-cache-manager-memory-store does not implement TTL at all, so all cache items would be kept in cache forever, won't they? This might be worth another issue & PR though. ;)

I haven't looked into the implementation, but wanted to note I tested the built-in memory store tonight using a TTL set on the memory store, and it worked successfully--it returned cached items within the TTL timeframe and returned undefined after the expected TTL elapsed. (Edit: I didn't test the OP's issue. Just confirming that memory cache doesn't cache forever.)

from cache-manager.

zzau13 avatar zzau13 commented on August 16, 2024

Fixes by #203

from cache-manager.

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.