Iteration with Expiration state #311
Replies: 1 comment 6 replies
-
Hi. Currently (as of moka v0.11.x), there is no way to get and set the frequency and TTL/TTI timers for cached entry. I will create feature requests (GitHub Issues) for them. For now, I think you can implement TTL/TTI part by using per-entry expiration policy. I will try to write a sample code later, but the basic idea will be to store your value with the last modified and last accessed timestamps. // You may need to use an async lock if you use `future::Cache` of
// v0.12.0 or newer, but I am not sure yet.
use std::sync::RwLock;
// You cannot use `std::time::Instant` as it cannot be converted to/
// from the wall-clock time.
use time::OffsetDateTime;
pub struct MyValue<V> {
value: V,
last_modified: OffsetDateTime,
last_accessed: RwLock<OffsetDateTime>,
} You will set these timestamps when When restoring the cache entries, sort the values by their Let me know which cache type you are using: |
Beta Was this translation helpful? Give feedback.
-
Similar as mentioned in #235, I try to store and read-in my Cache content locally during a re-start of my server. However, this means the expiration state will be reset: the frequency is set to zero and the TTL/TTI maximized. Would it be possible to iterate with Expiration state? So this state information can be stored too.
Beta Was this translation helpful? Give feedback.
All reactions