Skip to content

Commit

Permalink
Merge pull request #199 from 9999years/cache-remove-expiration
Browse files Browse the repository at this point in the history
Make `cache_set_lifespan` the inverse of `cache_get_lifespan`
  • Loading branch information
jaemk authored Apr 26, 2024
2 parents fdbfd57 + 8d065d2 commit 39d974c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ pub trait Cached<K, V> {
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64> {
None
}

/// Remove the lifespan for cached values, returns the old value.
///
/// For cache implementations that don't support retaining values indefinitely, this method is
/// a no-op.
fn cache_unset_lifespan(&mut self) -> Option<u64> {
None
}
}

/// Extra cache operations for types that implement `Clone`
Expand Down Expand Up @@ -434,10 +442,18 @@ pub trait IOCached<K, V> {
None
}

/// Set the lifespan of cached values, returns the old value
/// Set the lifespan of cached values, returns the old value.
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64> {
None
}

/// Remove the lifespan for cached values, returns the old value.
///
/// For cache implementations that don't support retaining values indefinitely, this method is
/// a no-op.
fn cache_unset_lifespan(&mut self) -> Option<u64> {
None
}
}

#[cfg(feature = "async")]
Expand All @@ -464,4 +480,12 @@ pub trait IOCachedAsync<K, V> {
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64> {
None
}

/// Remove the lifespan for cached values, returns the old value.
///
/// For cache implementations that don't support retaining values indefinitely, this method is
/// a no-op.
fn cache_unset_lifespan(&mut self) -> Option<u64> {
None
}
}
4 changes: 4 additions & 0 deletions src/stores/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ where
self.refresh = refresh;
old
}

fn cache_unset_lifespan(&mut self) -> Option<u64> {
self.seconds.take()
}
}

#[cfg(test)]
Expand Down

0 comments on commit 39d974c

Please sign in to comment.