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§
Sourcefn backend_type(&self) -> &'static str
fn backend_type(&self) -> &'static str
report the type of the cache backend
Sourcefn get(&self, key: CacheKey) -> Option<CacheValue>
fn get(&self, key: CacheKey) -> Option<CacheValue>
Get an image from the cache by its key
Sourcefn get_random(&self) -> Option<CacheValue>
fn get_random(&self) -> Option<CacheValue>
Get a random image from the cache
Sourcefn set(&mut self, key: CacheKey, image: CacheValue) -> Result<(), String>
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
Sourcefn remove(&mut self, key: &CacheKey) -> Option<CacheValue>
fn remove(&mut self, key: &CacheKey) -> Option<CacheValue>
Remove an image from the cache by its key