Trait CacheBackend

Source
pub trait CacheBackend:
    Debug
    + Send
    + Sync {
    // Required methods
    fn backend_type(&self) -> &'static str;
    fn new() -> Self
       where Self: Sized;
    fn get(&self, key: CacheKey) -> Option<CacheValue>;
    fn get_random(&self) -> Option<CacheValue>;
    fn set(&mut self, key: CacheKey, image: CacheValue) -> Result<(), String>;
    fn remove(&mut self, key: &CacheKey) -> Option<CacheValue>;
    fn size(&self) -> usize;
    fn keys(&self) -> &[CacheKey];
    fn clear(&mut self) -> Result<(), String>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}

Required Methods§

Source

fn backend_type(&self) -> &'static str

report the type of the cache backend

Source

fn new() -> Self
where Self: Sized,

Create a new cache backend

Source

fn get(&self, key: CacheKey) -> Option<CacheValue>

Get an image from the cache by its key

Source

fn get_random(&self) -> Option<CacheValue>

Get a random image from the cache

Source

fn set(&mut self, key: CacheKey, image: CacheValue) -> Result<(), String>

Store an image in the cache with its key

§Errors

Returns an error if the image cannot be stored (e.g. due to size limits), or if the image is invalid

Source

fn remove(&mut self, key: &CacheKey) -> Option<CacheValue>

Remove an image from the cache by its key

Source

fn size(&self) -> usize

Get the size of the cache

Source

fn keys(&self) -> &[CacheKey]

Retrieve the keys in the cache

Source

fn clear(&mut self) -> Result<(), String>

Clear the cache

§Errors

Returns an error if the cache cannot be cleared.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the cache is empty

Implementors§