JuliaCollections / LRUCache.jl

An implementation of an LRU Cache in Julia
Other
56 stars 23 forks source link

add optional callback method to notify evictions #1

Closed tanmaykm closed 3 years ago

tanmaykm commented 8 years ago

It is often useful to have notifications when an item is being evicted from the cache to cleanup some state or release resources.

With this PR, LRU cache can be created with an optional callback function which will be called when an item is being evicted from the cache.

Example:

julia> using LRUCache

julia> CACHE = LRU{Int, Int}(3; callback=(x,y)->println("removed $x=>$y"))
       for i in 1:4
           CACHE[i] = i*10
       end
removed 1=>10
tanmaykm commented 8 years ago

@jcrist any concerns with this PR?

Thanks for putting this package up. I am planning to use this in a couple of my own packages. It will be nice to have this feature merged and a new version tagged.

shashi commented 8 years ago

@jcrist ping

jcrist commented 8 years ago

Oop, sorry for the huge delay. This went to my old email, which I no longer use. Updated.

At first glance this looks fine. One passing thought is that at some point it might become necessary to have callbacks at other points. Perhaps one on entry to the cache as well. As such, it might be nice to have a more specific name. Perhaps on_exit as the keyword argument?

jcrist commented 8 years ago

Also, I no longer have the time/desire to maintain this project (no longer using Julia at work). If you're interested, I could give you contribute permissions and/or transfer the repo to somewhere else.

tk3369 commented 6 years ago

Hi jcrist - I am happy to contribute if you grant me permissions.

Krastanov commented 3 years ago

This can probably be closed now thanks to #23