DataCache

Struct DataCache 

Source
pub struct DataCache<K, V>
where K: Eq + Hash + Clone,
{ /* private fields */ }
Expand description

In-memory data cache

Implementations§

Source§

impl<K, V> DataCache<K, V>
where K: Eq + Hash + Clone,

Source

pub fn new(config: CacheConfig) -> Self

Source

pub fn get(&mut self, key: &K) -> Option<&V>

Get a value from cache

Source

pub fn get_with_state(&mut self, key: &K) -> Option<(&V, CacheState)>

Get a value and its state

Source

pub fn contains(&self, key: &K) -> bool

Check if key exists and is not expired

Source

pub fn insert(&mut self, key: K, value: V, options: CacheOptions)
where V: CacheSize,

Insert a value into cache

Source

pub fn insert_default(&mut self, key: K, value: V)
where V: CacheSize,

Insert with default options

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Remove a value from cache

Source

pub fn invalidate_tag(&mut self, tag: &str) -> usize

Invalidate entries by tag

Source

pub fn clear(&mut self)

Clear all entries

Source

pub fn stats(&self) -> &CacheStats

Get cache statistics

Source

pub fn len(&self) -> usize

Get number of entries

Source

pub fn is_empty(&self) -> bool

Check if cache is empty

Source

pub fn memory_usage(&self) -> usize

Get current memory usage

Source

pub fn tick(&mut self, delta_ms: u64)

Update timestamp (call each frame or periodically)

Source

pub fn set_timestamp(&mut self, timestamp: u64)

Set timestamp directly

Source

pub fn timestamp(&self) -> u64

Get current timestamp

Source

pub fn on_event(&mut self, callback: CacheCallback)

Add event listener

Trait Implementations§

Source§

impl<K, V> Default for DataCache<K, V>
where K: Eq + Hash + Clone,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for DataCache<K, V>

§

impl<K, V> !RefUnwindSafe for DataCache<K, V>

§

impl<K, V> Send for DataCache<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for DataCache<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for DataCache<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for DataCache<K, V>

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