Trait CacheSource

Source
pub trait CacheSource:
    'static
    + Send
    + Sync {
    type Value: 'static;

    // Required method
    fn load(&self, id: &str, create: bool) -> Result<Self::Value>;

    // Provided methods
    fn unload(&self, _id: &str, _obj: &Self::Value) -> Result<()> { ... }
    fn remove(&self, _id: &str) -> Result<()> { ... }
}
Expand description

A source where cache can be generated from.

Required Associated Types§

Source

type Value: 'static

Required Methods§

Source

fn load(&self, id: &str, create: bool) -> Result<Self::Value>

Create a new cached object. Return a value defined by default configurations if create is set. In the course of creation, no state should be stored out of RAM, e.g., writing to files or calling to remote machines.

Provided Methods§

Source

fn unload(&self, _id: &str, _obj: &Self::Value) -> Result<()>

Unload a cached object. Implementations should write the value into a recoverable form of storage, e.g., serializing data into JSON, if necessary. Cache unloading is an optional process.

Source

fn remove(&self, _id: &str) -> Result<()>

Remove a cached object. Implementations should remove any associated data from storage and invalidate any recoverability. If a resource doesn’t exist, the source shouldn’t report an error. Cache removal is an optional process.

Implementors§

Source§

impl<T: 'static + Send + Sync> CacheSource for DumbCacheSource<T>

Source§

type Value = T