Struct ReactorCache

Source
pub struct ReactorCache<K, V, E> { /* private fields */ }

Implementations§

Source§

impl<K: Clone + Eq + Hash, V: Weighted, E: Clone + Debug> ReactorCache<K, V, E>

Core methods for interacting with the cache

Source

pub fn new(capacity: usize, handle: Handle) -> Self
where K: 'static, V: 'static, E: 'static,

Creates a new Reactor Cache with the given capacity, which runs in handle’s event-loop

Source

pub fn stats(&self) -> Receiver<CacheStats>

Returns a future with a snapshot of the cache’s stats. No guarnatees are made about when the snapshot is taken.

§Example

Run a future that logs the cache stats:

    let mut core = Core::new().expect("meltdown");
    let cache = ReactorCache::<Int, Int, ()>::new(10, core.handle());
    core.run(cache.stats().map(|s| println!("{:?}",s))).unwrap();
Source

pub fn get(&self, k: K) -> GetHandle<V, E>

Returns a future with a snapshot of the cache’s stats. No guarnatees are made about when the snapshot is taken.

§Example

Run a future that logs the cache stats:

    let mut core = Core::new().expect("meltdown");
    let cache = ReactorCache::<Int, Int, ()>::new(10, core.handle());
    core.run(cache.load_fn(Int(1), ||
    core.run(cache.stats().map(|s| println!("{:?}",s))).unwrap();
Source

pub fn get_if_resident(&self, k: K) -> GetHandle<V, E>

Source

pub fn load_fn<F, T>(&self, k: K, f: F) -> LoadHandle<Lazy<F, T>, V, E>
where F: 'static + Send + FnOnce() -> T, T: 'static + IntoFuture<Item = V, Error = E>, T::Future: 'static + Send,

Source

pub fn load<F>(&self, k: K, f: F) -> LoadHandle<F, V, E>
where F: Future<Item = V, Error = E>,

Source

pub fn evict(&self, k: K) -> Receiver<()>

Auto Trait Implementations§

§

impl<K, V, E> Freeze for ReactorCache<K, V, E>

§

impl<K, V, E> RefUnwindSafe for ReactorCache<K, V, E>

§

impl<K, V, E> Send for ReactorCache<K, V, E>
where K: Send, E: Send, V: Sync + Send,

§

impl<K, V, E> Sync for ReactorCache<K, V, E>
where K: Send, E: Send, V: Sync + Send,

§

impl<K, V, E> Unpin for ReactorCache<K, V, E>

§

impl<K, V, E> UnwindSafe for ReactorCache<K, V, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.