Comments (10)
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.
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.
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.
Any updates on this? Seems like a pretty big problem for multi-caching...
from cache-manager.
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.
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.
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.
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.
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.
Fixes by #203
from cache-manager.
Related Issues (20)
- Why `Promise` object cannot be store correctly? HOT 2
- prefix configuration option for cache keys HOT 3
- Fs cache store engine HOT 1
- Value being set inside "v" field on new version v2 HOT 2
- Map object is not stored HOT 5
- `this.cacheManager.store.client` is undefined HOT 2
- Question: are expired items removed from the in-memory store?
- Bug in docs: "Create single cache store synchronously" doesn't pass options to store HOT 1
- Broken link for 'Example Express App Usage' in README.md HOT 1
- Update TypeScript compilation target years HOT 2
- Receiving error `SyntaxError: Unexpected token 'export'` with v5.6.0 HOT 8
- Malformed cache data HOT 12
- Del with using keyPrefix doesn't work as expected HOT 1
- Version 5.7.2 requires node >= 20 HOT 4
- Question: how to have memory cache with dynamic TTL?
- Question: how to have memory cache with dynamic TTL? HOT 1
- Broken links in NPM docs HOT 2
- There is an issue with the `cache-manager` option is expected to be an object, but the type hint in the library indicates it should be a number. HOT 1
- cache.wrap is shared between cache instances HOT 1
- NestJS microservice gives unclear error when trying to start without Redis running HOT 3
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 cache-manager.