-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Evict callback for TTLCache #205
Comments
If I understand the docs correctly, items are only evicted by timeout when you try to access them but the item has expired. So, the method you would need to override is |
@arossert Sorry, there is no way to get notified when a |
@tkem Thanks for the update, it will be a coll feature to add 😃 |
To take this into consideration, somebody would have to come up with a really good use case... |
Yes, it would be nice to have this @tkem. (It would also be nice if cachetools didn't use double underscores on member fields as this makes it less friendly to subclassing.) I'm using TTLCache as trick to doing a TTL-based connection pool, and I'd like to close a connection as soon as it's evicted, rather than waiting till it is garbage collected. |
eh, on second thought, there's too many edge cases to worry about (delitem, setitem, expire, and more). I'll stick with "wait for gc" and see if that suffices for me. |
I think there are many examples you can think of. For example waiting for a async request response with req_id key. If the response does not come within a timeout then evict the cache. I would like to know what requests I didn't know have a reply and were droped. It would be very usefull to be able at least to log that. |
In my case, I'm using the |
if TTLCache is not timer-based, then there is no event that one could "subscribe to" inside the code. Based on this comment: #205 (comment) i believe that this is not the case, and so i think it will be misleading to offer a "on('expired')" callback for TTLCache, as the frequency will not be deterministic. Please correct me if i am wrong, because i also have a use case for using such function in TTLCache. And basically i dont want to handle a pool of Timers myself. all in all, you could look at this library as an alternative depending on your use case: https://github.com/dbader/schedule |
How is that misleading? No matter what is the eviction policy I would like to know when the case was evicted. If the frequency is not deterministic then having a callback is actually more useful. |
i see your point, perhaps using good naming conventions could prevent misunderstandings, or perhaps a big disclaimer on the documentation of such an event hook could do the job :) cheers |
I can see this to be very useful |
I'm missing the option to set a callback when an item is evicted using the
TTLCache
.I tried using the solution detailed here but it seems that the
TTLCache
is working a bit differently then the others and not calling thepopitem()
when entries are evicted by timeout.Is there a way to get a callback when an item is deleted also by timeout?
I tried overriding the
expire()
function with no success.The text was updated successfully, but these errors were encountered: