Skip to main content

Cache

Trait Cache 

Source
pub trait Cache {
    // Required methods
    fn save(&self, key: &str, value: Vec<u8>) -> Result<(), CacheError>;
    fn get(&self, key: &str) -> Option<Vec<u8>>;
    fn delete(&self, key: &str) -> Option<Vec<u8>>;
    fn purge(&self);
}
Expand description

Represents a cache. It stores each element as a new entry.

Required Methods§

Source

fn save(&self, key: &str, value: Vec<u8>) -> Result<(), CacheError>

Stores value in cache with provided key. Value should be already serialized.

If it already exists, stored value will be overridden with the new param value. Have in consideration that this might affect the Cache order, depending on the eviction strategy (i.e. LIFO, FIFO or LRU caches). Currently, only FIFO cache is offered.

If it is not possible to store the value in cache, it results in a CacheError.

Source

fn get(&self, key: &str) -> Option<Vec<u8>>

Returns stored value in cache for provided key.

If it exists in the cache, returns Some with bytes slice value. Otherwise, it returns None.

Source

fn delete(&self, key: &str) -> Option<Vec<u8>>

Removes an element from cache by key.

Returns the deleted value if present, or None otherwise.

Source

fn purge(&self)

Clears all elements in cache.

Implementors§