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

[feature request] add Cache::get_with_if(&self, key: &K, fallback: Fut, cond: Fn(&V) -> bool) -> V method #123

Closed
ClSlaid opened this issue May 15, 2022 · 2 comments · Fixed by #124
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ClSlaid
Copy link
Contributor

ClSlaid commented May 15, 2022

I'm building a cache whose entries have their own standalone TTL. However moka supports global TTL and IDLE only. So I'm here to propose a new method Cache::get_with_if(&self, key: &K, fallback: Fut, cond: Fn(&V) -> bool) -> V

The function works like Cache::get_with(&self, key: &K, init: Fut) -> V, but when the key does not exist or cond(&V) is true, the init clojure will be called to initialize the value.

@ClSlaid ClSlaid changed the title [feature request] add Cache::get_with_if(&self, key: &K, fallback: Fut, cond: Fn(&V) -> bool) -> V support [feature request] add Cache::get_with_if(&self, key: &K, fallback: Fut, cond: Fn(&V) -> bool) -> V method May 15, 2022
@tatsuya6502 tatsuya6502 added the enhancement New feature or request label May 15, 2022
@tatsuya6502
Copy link
Member

Thank you for proposing get_with_if method. I think it will be easy to implement. Let me work on it.

I'm building a cache whose entries have their own standalone TTL. However moka supports global TTL and IDLE only.

You are right. Per-entry expiration is on our roadmap but currently scheduled very late. (The item 10: "(post v1.0) feat: The variable (per-entry) expiration, using a hierarchical timer wheel") I will probably give it more priority. But anyway, I will implement get_with_if for now.

@tatsuya6502
Copy link
Member

Hi @ClSlaid — I have published Moka v0.8.4 to crates.io with the get_with_if method. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants