cached icon indicating copy to clipboard operation
cached copied to clipboard

Cron-like cache clearing

Open arxdeus opened this issue 3 years ago • 1 comments

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

arxdeus avatar Dec 25 '22 20:12 arxdeus

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) https://github.com/jaemk/cached/blob/bb0e525ea9d9f548a1a8dcce673eb5e918e688d5/examples/basic_proc_macro.rs#L37, and then calls “flush”

jaemk avatar Dec 25 '22 22:12 jaemk