Closed trevor-scheer closed 4 months ago
Yeah, could be documented better.
In practice, 0
means "no TTL", and is the default.
Via ttl documentation - https://github.com/isaacs/node-lru-cache?tab=readme-ov-file#ttl:
Max time to live for items before they are considered stale.
If 0
is the default value, then does that mean whatever I store in the cache, will the item be considered as stale?
Yes, zero is the default, which means (on a single item, or the cache as a whole) "do not do track TTL", not "go stale immediately".
It can be any non-negative integer, not just positive, that's a inaccuracy in the docs.
Awesome! @isaacs One last question - and if you dont get to it, its fine
If my configuration is only { max: 100 }
, then would has(key)
only be an existence look up? Since ttl
would be defaulted to 0
I just want to check if a key is in the cache and with no other side effects
Yes. has()
checks for presence without updating recency. (I think that's maybe configurable iirc?)
Seeking clarification on the
ttl
option. TheREADME
states "positive integer only" but in code it defaults to0
, suggesting0
is also valid (even if it means the same asundefined
. Elsewhere, i.e. theMilliseconds
type also states "positive integer only".Happy to open a PR, just looking for clarity on the expectation/intent before I do (unless you think everything is correct as it stands).