Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cache_set_lifespan the inverse of cache_get_lifespan #199

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading