[−][src]Struct xfetch::CacheEntry
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::new(|| 42) .with_ttl(|_| Duration::from_secs(10)) .build();
See the module-level documentation for more information.
Methods
impl<T> CacheEntry<T>
[src]
pub fn new<F>(f: F) -> CacheEntryBuilder<T> where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
Return a new CacheEntryBuilder.
This method takes a closure which should return the value to be cached.
pub fn is_expired(&self) -> bool
[src]
Check whether the cache has expired or not.
With probabilstic early expiration, this method may return true
before
the entry is really expired.
pub fn is_eternal(&self) -> bool
[src]
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.
pub fn get(&self) -> &T
[src]
Returns a reference of the contained value.
pub fn into_inner(self) -> T
[src]
Unwraps the value.
Trait Implementations
impl<T: Copy> Copy for CacheEntry<T>
[src]
impl<T: Clone> Clone for CacheEntry<T>
[src]
fn clone(&self) -> CacheEntry<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<T> Send for CacheEntry<T> where
T: Send,
T: Send,
impl<T> Sync for CacheEntry<T> where
T: Sync,
T: Sync,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,