pub struct CacheEntry<T> { /* private fields */ }
Expand description
A cache entry that employs probabilistic early expiration
§Examples
In this example, you can see how to create a new cache entry. The value of
the entry is passed in as a closure so the time required for recomputation
can be measured. The time to expiration can be set by chaining the
with_ttl()
method.
use std::time::Duration;
use xfetch::CacheEntry;
let entry = CacheEntry::builder(|| 42)
.with_ttl(|_| Duration::from_secs(10))
.build();
See the module-level documentation for more information.
Implementations§
Source§impl<T> CacheEntry<T>
impl<T> CacheEntry<T>
Sourcepub fn builder<F>(f: F) -> CacheEntryBuilder<T>where
F: FnOnce() -> T,
pub fn builder<F>(f: F) -> CacheEntryBuilder<T>where
F: FnOnce() -> T,
Return a new CacheEntryBuilder.
This method takes a closure which should return the value to be cached.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check whether the cache has expired or not.
With probabilstic early expiration, this method may return true
before
the entry is really expired.
Sourcepub fn is_eternal(&self) -> bool
pub fn is_eternal(&self) -> bool
Check if the cache entry will never expire.
If the cache entry is created without setting time to expiration then it is a eternal cache entry.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the value.
Trait Implementations§
Source§impl<T: Clone> Clone for CacheEntry<T>
impl<T: Clone> Clone for CacheEntry<T>
Source§fn clone(&self) -> CacheEntry<T>
fn clone(&self) -> CacheEntry<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more