dial-once/node-cache-manager-redis

wrap with {ttl: 0} is caching forever

pasupulaphani opened this issue · 7 comments

redisCache.wrap("key", () => Promise.resolve("hit"), {ttl: 0});

@pasupulaphani Would you mind giving us a code example here to check ?

@mrister Added sample code.

This is expected behaviour as having a ttl of 0 makes no sense (why would you store something that is to be deleted instantly?). So 0 was defined as 'infinite'

Can you describe what you are trying to achieve? Because I fail to see the benefits of using the cache module to not cache 😆

I wasn't deliberate in doing that. Found this when testing edge cases.

I wouldn't recommend making the assumption 0 as 'infinite'. Only suggesting. Feel free to close the issue if you feel this is not one.

Thing is with redis TTL of -1 and -2 have a meaning: http://redis.io/commands/ttl, as well as positive integers.

About 0 = infinite, the mother module (node-cache-manager) works this ways on its memory cache, it makes sense to me to be consistent with it and use the same API.

Why do you recommend to avoid using ttl: 0 as an infinite ttl value?

Thank you for the explanation. I can see now why it is implemented this way.