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

Feature request: distinguish between manual removal and natural LRU eviction #180

Open
jamesmoessis opened this issue Aug 21, 2024 · 1 comment

Comments

@jamesmoessis
Copy link

Wondering if you would accept a PR for the following:

My use case is that I don't want the eviction callback to be called when I am manually calling c.Remove(k), only when natural LRU eviction occurs. Reasoning: I have a metric of how long something stays on the LRU cache. Then if I manually Remove() from the cache, this metric is polluted because now it doesn't track the natural LRU eviction time, but just the time since insertion of the key.

Would you accept a PR to add a new method to the simple cache, for example a Delete() or RemoveWithoutEvictCB() method. I would be happy to contribute, cheers!

@bep
Copy link

bep commented Feb 2, 2025

Would you accept a PR to add a new method to the simple cache, for example a Delete() or RemoveWithoutEvictCB() method. I would be happy to contribute, cheers!

I have add a similar need, but I suspect it would be better to expand the callback function, e.g.

OnEvict func(key K, value V)

To

OnEvict func(key K, value V, source int)

Where source is a constant (e.g. remove). It would be a breaking change, but very easy to adapt to (just drop the source value if you don't care).

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