Skip to main content

WriteThroughCache

Struct WriteThroughCache 

Source
pub struct WriteThroughCache<S, C> { /* private fields */ }
Expand description

A cache adapter that propagates writes to a backing KvStore immediately.

  • put(k, v) → writes to both the cache and the store.
  • get(k) → returns from cache if present; on miss, fetches from the store, populates the cache, and returns the value.
  • remove(k) → removes from both cache and store.

§Type parameters

  • S: a KvStore implementor.
  • C: a Cache<Vec<u8>, Vec<u8>> implementor.

Implementations§

Source§

impl<S, C> WriteThroughCache<S, C>
where S: KvStore, C: Cache<Vec<u8>, Vec<u8>>,

Source

pub fn new(store: S, cache: C) -> Self

Create a new write-through cache adapter.

Source

pub fn store(&self) -> &S

Borrow the inner store.

Source

pub fn cache(&self) -> &C

Borrow the inner cache.

Source

pub fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>, StoreError>

Look up key: cache first, then store on miss.

On a store hit the value is populated back into the cache.

Source

pub fn put(&mut self, key: Vec<u8>, value: Vec<u8>) -> Result<(), StoreError>

Insert keyvalue into both cache and store.

Source

pub fn remove(&mut self, key: &[u8]) -> Result<(), StoreError>

Remove key from both cache and store.

Source

pub fn cache_len(&self) -> usize

Return the number of live cache entries.

Auto Trait Implementations§

§

impl<S, C> Freeze for WriteThroughCache<S, C>
where S: Freeze, C: Freeze,

§

impl<S, C> RefUnwindSafe for WriteThroughCache<S, C>

§

impl<S, C> Send for WriteThroughCache<S, C>
where S: Send, C: Send,

§

impl<S, C> Sync for WriteThroughCache<S, C>
where S: Sync, C: Sync,

§

impl<S, C> Unpin for WriteThroughCache<S, C>
where S: Unpin, C: Unpin,

§

impl<S, C> UnsafeUnpin for WriteThroughCache<S, C>
where S: UnsafeUnpin, C: UnsafeUnpin,

§

impl<S, C> UnwindSafe for WriteThroughCache<S, C>
where S: UnwindSafe, C: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.