bentocache icon indicating copy to clipboard operation
bentocache copied to clipboard

Memory Cache Forever Issue

Open imconnorngl opened this issue 1 year ago • 0 comments

When implementing a "forever" cache in using the memoryDriver. I recently came across some interesting behaviour, which led to me implementing the other caches in my program incorrectly causing caches to not be hit.

When using the getOrSetForever method. You are currently forced to provide ttl: undefined in the options, since Infinity. is not accepted by the LRUCache library. Without doing this the memory cache defaults to a super short ttl. image image

However, when using ttl: undefined on other adapters, such as the knexDriver. ttl: undefined is treated as no TTL, and that causes cache misses to occur, so when I implemented that driver I was experiencing cache misses, since it needs to have a default of ttl: Infinity image

TLDR: The default TTL on the memoryDriver should be undefined rather than Number.POSITIVE_INFINITY.

imconnorngl avatar Jun 14 '24 13:06 imconnorngl