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.
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.
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.