You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ended up implementing my own cache type that stores Arcs and only evicts from the cache if the ttl is passed AND if the strong count is 1, in which case it can safely unwrap the Arc.
I am glad you found a solution. Perhaps, I should have shown you the sample code on this comment (#344). It uses dashmap::DashMap to store the keys and Arcs, and use moka::sync::Cache to control the TTL of the entries in the DashMap. It does not store the Arcs on moka cache, so it does not have the strong count problem.
The sample code does not exactly match your use case, because moka cache cannot delay the eviction until the strong count becomes 1. You will have to reinsert the evicted entry like this one (#298), so it is not an elegant solution.
After #298 was filed, I was thinking to add a support for an event handler closure, which will be called when a cached entry is about to expire by the TTL (but is not yet evicted). The handler can then check the strong count of the Arc to decide whether it lets the entry to be evicted or extends its expiry.
The text was updated successfully, but these errors were encountered:
tatsuya6502
changed the title
Add support for something like an event handler, which can be used to refresh expiring entry, for example?
Add support for something like an event handler, which can be used to refresh expiring entry?
Jan 19, 2024
#372 (comment)
CC: @unikzforce @rtdavis22
The text was updated successfully, but these errors were encountered: