[][src]Struct xfetch::CacheEntry

pub struct CacheEntry<T> { /* fields omitted */ }

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]

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_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

impl<T> Sync for CacheEntry<T> where
    T: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]