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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.