Trait writium_cache::CacheSource [] [src]

pub trait CacheSource: 'static + Send + Sync {
    type Value: 'static;
    fn load(&self, id: &str, create: bool) -> Result<Self::Value>;

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

A source where cache can be generated from.

Associated Types

Required Methods

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

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.

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