Skip to content

Commit

Permalink
Conditionally notify TTL background job (#44)
Browse files Browse the repository at this point in the history
* Conditionally notify ttl job

* Update src/store.rs

Co-authored-by: Christian Gill <[email protected]>

---------

Co-authored-by: Christian Gill <[email protected]>
  • Loading branch information
ndelvalle and gillchristian authored Jun 12, 2024
1 parent 10c907e commit 82918f3
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_to_expire = state.ttls.iter().next().map(|(_, key)| key);
let expires_next = next_to_expire == Some(&key);
if expires_next {
self.waker.notify_one();
}
}
}

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

0 comments on commit 82918f3

Please sign in to comment.