pub struct CustomCache { /* private fields */ }Expand description
This module provides various cache implementations and a shared DEKCacheTrait
for storing and retrieving data by an identifier.
A custom cache that implements the DEKCacheTrait.
This structure provides a flexible caching mechanism that delegates to user-defined closures for retrieving and storing data.
Implementations§
Source§impl CustomCache
Implementations for creating and working with a CustomCache.
impl CustomCache
Implementations for creating and working with a CustomCache.
Sourcepub fn new<G, S>(get_fn: G, set_fn: S) -> Self
pub fn new<G, S>(get_fn: G, set_fn: S) -> Self
Creates a new CustomCache with the specified get and set closures.
§Arguments
get_fn- A closure that receives a&Stringreference to a key and returns an optionalVec<u8>of data.set_fn- A closure that receives aStringkey and aVec<u8>to store, returning aResultwith either the stored data or aCacheError.
§Returns
A CustomCache instance configured with the provided closures.
Trait Implementations§
Source§impl DEKCacheTrait for CustomCache
impl DEKCacheTrait for CustomCache
Source§fn get(&self, k: &String) -> Option<Vec<u8>>
fn get(&self, k: &String) -> Option<Vec<u8>>
Retrieves data from the cache for the provided key.
§Arguments
k- A reference to the string key for which data should be retrieved.
§Returns
An Option<Vec<u8>> containing the cached data if found, or None if not present.
Source§fn set(&self, k: String, v: Vec<u8>) -> Result<Vec<u8>, CacheError>
fn set(&self, k: String, v: Vec<u8>) -> Result<Vec<u8>, CacheError>
Stores data in the cache for the given key.
§Arguments
k- A string key under which the value should be stored.v- A vector of bytes representing the data to be cached.
§Returns
A Result<Vec<u8>, CacheError> indicating either successful storage (with the stored bytes)
or a CacheError if something went wrong.