#Does cache entry get deleted after TTL expires with @nestjs/cache-manager?
6 messages · Page 1 of 1 (latest)
Depending on the store you're using.
Redis, for example has internal expiration mechanism, and expired keys are eventually garbage collected (deleted) once they expire: https://stackoverflow.com/a/36173972/2078771
I'm using the built-in store
That would be the memory store, which uses lru-cache under the hood.
You could set https://github.com/isaacs/node-lru-cache#ttlautopurge to make sure keys are deleted once they expire, but it's probably not a good idea:
Note that this may significantly degrade performance, especially if the cache is storing a large number of items. It is almost always best to just leave the stale items in the cache, and let them fall out as new items are added.
Why do you care about deleting expired keys?
I'm storing valid JWT in cahce to speed up responses after the first verification. It might lead to some trouble if I have old invalid entries flying around there.
With the default configuration, you won't get them back with .get() after the specified ttl.
They'll still be in the memory somewhere, but you won't get them using the standard methods.