Skip to content
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

Add support for something like an event handler, which can be used to refresh expiring entry? #381

Open
tatsuya6502 opened this issue Jan 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tatsuya6502
Copy link
Member

#372 (comment)

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.

CC: @unikzforce @rtdavis22

@tatsuya6502 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
@tatsuya6502 tatsuya6502 added the enhancement New feature or request label Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant