Does .insert
reset the TTL time?
#410
-
If I call |
Beta Was this translation helpful? Give feedback.
Answered by
tatsuya6502
Apr 7, 2024
Replies: 1 comment
-
Thank you for using moka.
Yes, the item's TTL must be updated. Here is an unit test: https://github.com/moka-rs/moka/blob/v0.12.5/src/sync/cache.rs#L2470-L2491
let mut cache = Cache::builder()
.max_capacity(100)
.time_to_live(Duration::from_secs(10))
.eviction_listener(listener)
.build();
...
cache.insert("b", "bob");
cache.run_pending_tasks();
assert_eq!(cache.entry_count(), 1);
mock.increment(Duration::from_secs(5)); // 15 secs.
cache.run_pending_tasks();
assert_eq!(cache.get(&"b"), Some("bob"));
assert!(cache.contains_key(&"b"));
assert_eq!(cache.entry_count(), 1);
cache.insert("b", "bill");
expected.push((Arc::new("b"), "bob", RemovalCause::Replaced));
cache.run_pending_tasks();
mock.increment(Duration::from_secs(5)); // 20 secs
cache.run_pending_tasks();
assert_eq!(cache.get(&"b"), Some("bill"));
assert!(cache.contains_key(&"b"));
assert_eq!(cache.entry_count(), 1); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tqwewe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for using moka.
Yes, the item's TTL must be updated.
Here is an unit test: https://github.com/moka-rs/moka/blob/v0.12.5/src/sync/cache.rs#L2470-L2491