Skip to main content

CustomCache

Struct CustomCache 

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

Source

pub fn new<G, S>(get_fn: G, set_fn: S) -> Self
where G: Fn(&String) -> Option<Vec<u8>> + Send + Sync + 'static, S: Fn(String, Vec<u8>) -> Result<Vec<u8>, CacheError> + Send + Sync + 'static,

Creates a new CustomCache with the specified get and set closures.

§Arguments
  • get_fn - A closure that receives a &String reference to a key and returns an optional Vec<u8> of data.
  • set_fn - A closure that receives a String key and a Vec<u8> to store, returning a Result with either the stored data or a CacheError.
§Returns

A CustomCache instance configured with the provided closures.

Trait Implementations§

Source§

impl DEKCacheTrait for CustomCache

Source§

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>

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.

Source§

type Identifier = String

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V