-
-
Notifications
You must be signed in to change notification settings - Fork 90
Description
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 theArc
.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 andArc
s, and usemoka::sync::Cache
to control the TTL of the entries in theDashMap
. It does not store theArc
s 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.