Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ttl documentation #316

Open
trevor-scheer opened this issue Sep 14, 2023 · 5 comments
Open

ttl documentation #316

trevor-scheer opened this issue Sep 14, 2023 · 5 comments

Comments

@trevor-scheer
Copy link

Seeking clarification on the ttl option. The README states "positive integer only" but in code it defaults to 0, suggesting 0 is also valid (even if it means the same as undefined. Elsewhere, i.e. the Milliseconds 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).

@isaacs
Copy link
Owner

isaacs commented Sep 14, 2023

Yeah, could be documented better.

In practice, 0 means "no TTL", and is the default.

@nsunga
Copy link

nsunga commented Feb 15, 2024

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?

@isaacs
Copy link
Owner

isaacs commented Feb 15, 2024

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.

@nsunga
Copy link

nsunga commented Feb 15, 2024

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

@isaacs
Copy link
Owner

isaacs commented Feb 15, 2024

Yes. has() checks for presence without updating recency. (I think that's maybe configurable iirc?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants