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

Cron-like cache clearing #141

Open
kitsuniru opened this issue Dec 25, 2022 · 1 comment
Open

Cron-like cache clearing #141

kitsuniru opened this issue Dec 25, 2022 · 1 comment

Comments

@kitsuniru
Copy link

Hi, is it possible to implement cron-like clearing/resetting our cache?
It will be good to clear cache, for example, every hour

I don't mean the lifetime of the cached items, i mean a direct check for expired from the current time to the next "necessary", for example, clearing the entire cache every 15th minute of every hour, regardless of when the object was cached

@jaemk
Copy link
Owner

jaemk commented Dec 25, 2022

If you want to clear expired items, the timed and timed-sized stores have a flush method to do so: https://docs.rs/cached/latest/cached/struct.TimedSizedCache.html#method.flush. I don’t want to add functionality beyond that though since it becomes dependent on how you would prefer background tasks be run. You can either spawn a thread or a task that loops, sleeps 15m, acquires the cache lock (if the function is async, then the lock is also async)

let cache = SLOW_FN.lock().unwrap();
, and then calls “flush”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants