jaredwray/cacheable

Question: are expired items removed from the in-memory store?

Juraj-Masiar opened this issue · 0 comments

I'm tracking down some slow memory leak and I suspect it's coming from my huge cache.
I'm using short ttl, but I have a feeling it's not fully supported.
What backend is used for the example case?

// Create memory cache synchronously
const memoryCache = createCache(memoryStore(), {
  max: 100,
  ttl: 10 * 1000 /*milliseconds*/,
});

Because the "node-cache-manager-memory-store" says "TTL is not supported":
https://github.com/theogravity/node-cache-manager-memory-store

And the "node-lru-cache" says it's not deleting old items when they get stale:
https://github.com/isaacs/node-lru-cache?tab=readme-ov-file#ttl

EDIT:
Never mind, I've just found ttlAutopurge option that does what I need:

        /**
         * Preemptively remove stale items from the cache.
         * 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.
         *
         * Note that this means that {@link OptionsBase.allowStale} is a bit
         * pointless, as stale items will be deleted almost as soon as they
         * expire.
         *
         * @default false
         */
        ttlAutopurge?: boolean;