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
type Value: 'static
Required Methods
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
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.
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
impl<T: 'static + Send + Sync> CacheSource for DumbCacheSource<T> type Value = T;