phuslu / lru

High performance LRU cache
MIT License
189 stars 7 forks source link

[Feature Request] onevict, callback feature #7

Open ouvaa opened 6 months ago

ouvaa commented 6 months ago

possible to have an onevict call back feature for both the ttl and non ttl version?

phuslu commented 6 months ago

I've been thinking about this idea for a long time, but I haven't done it yet.

  1. phuslu/lru does not have an real(active) evict policy. If a WithEvict Option is provided, users may misunderstand/complain about why the item not being evicted when the TTL expires.
  2. Considering the above, I need a good Option name to avoid misuse/misunderstanding. I don’t have a good idea yet. Maybe WithListener is a potential candidate.
phuslu commented 6 months ago

maybe I need to implement a simple/cheap evict policy in future, e.g. a random scan policy which similar with redis.

ouvaa commented 6 months ago

@phuslu chatgpt can help suggest some good names.

izturn commented 4 months ago

any progress?

esp32wrangler commented 3 months ago

It is easy to implement some scanner feature in/around a wrapper if some user really needs it, but to allow that, there has to be at least a callback when an item is evicted before expiration. So please add at least that callback, or give us some pointers on how it would be easiest to implement it.