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

Why does Contains() method documentation talks about eviction #123

Open
viralmutant opened this issue Mar 3, 2023 · 2 comments
Open

Why does Contains() method documentation talks about eviction #123

viralmutant opened this issue Mar 3, 2023 · 2 comments

Comments

@viralmutant
Copy link
Contributor

Going through the documentation, I am bit confused about the wording in there

Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.

AFAIK, eviction in LRU happens only on addition.

If that is correct, why do we even mention eviction while checking for presence with Contains() method.

Is there any LRU that marks elements as stale without deleting them ? And evicts them while checking for presence ?

@jefferai
Copy link
Member

jefferai commented Mar 6, 2023

When you call Get it updates the recent-ness of the item...after all this is an LRU. The documentation for Contains is indicating that it does not do this, so calling it will not affect whether it's considered least recently used or not. It also won't trigger an eviction, as in, it won't check to ensure if the eviction process needs to be run.

The docs are simply being explicit is all.

@viralmutant
Copy link
Contributor Author

Yes, I understand the recent-ness part and that is necessary for the documentation. But I was confused why eviction was mentioned under Contains. We don't mention eviction under Get() method and under Peek() method, and that is understood.
So when I found eviction statement under Contains, I thought maybe we have lazy eviction wherein the keys are removed on access, if they are stale. That is why I wanted to clarify.

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

2 participants