Skip to content

Commit

Permalink
Conditionally notify ttl job
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelvalle committed Jun 5, 2024
1 parent 10c907e commit 4814397
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,18 @@ impl InnerStore {
}

pub fn set2(&self, key: Key, value: NewValue) {
let has_ttl = value.ttl.is_some();
let mut state = self.lock();
state.set2(key, value);
self.waker.notify_one();

state.set2(key.clone(), value);

if has_ttl {
let next_expiring_key = state.ttls.iter().next().map(|(_, key)| key);
let is_next_expiring_key = next_expiring_key == Some(&key);
if is_next_expiring_key {
self.waker.notify_one();
}
}
}

pub fn incr_by<T>(&self, key: &str, increment: T) -> Result<T, String>
Expand Down

0 comments on commit 4814397

Please sign in to comment.