diff --git a/src/lib.rs b/src/lib.rs index 5ef9bc7..a4ae617 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,6 +373,14 @@ pub trait Cached { fn cache_set_lifespan(&mut self, _seconds: u64) -> Option { 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 { + None + } } /// Extra cache operations for types that implement `Clone` @@ -434,10 +442,18 @@ pub trait IOCached { 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 { 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 { + None + } } #[cfg(feature = "async")] @@ -464,4 +480,12 @@ pub trait IOCachedAsync { fn cache_set_lifespan(&mut self, _seconds: u64) -> Option { 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 { + None + } } diff --git a/src/stores/disk.rs b/src/stores/disk.rs index 47628f6..5b204fb 100644 --- a/src/stores/disk.rs +++ b/src/stores/disk.rs @@ -364,6 +364,10 @@ where self.refresh = refresh; old } + + fn cache_unset_lifespan(&mut self) -> Option { + self.seconds.take() + } } #[cfg(test)]