Skip to main content

CacheEntry

Struct CacheEntry 

Source
pub struct CacheEntry<K, V, M = ()>
where K: Clone + Hash + Eq, V: Clone, M: Clone,
{ pub key: K, pub value: V, pub metadata: M, pub timestamp: DateTime<Utc>, pub expiry: Option<DateTime<Utc>>, pub access_count: u64, pub last_accessed: DateTime<Utc>, }
Expand description

A cache entry containing a key-value pair with metadata

Fields§

§key: K

The cache key

§value: V

The cached value

§metadata: M

Optional metadata associated with the entry

§timestamp: DateTime<Utc>

Timestamp when the entry was created

§expiry: Option<DateTime<Utc>>

Optional expiry time for TTL-based eviction

§access_count: u64

Number of times this entry has been accessed

§last_accessed: DateTime<Utc>

Last access timestamp

Implementations§

Source§

impl<K, V, M> CacheEntry<K, V, M>
where K: Clone + Hash + Eq, V: Clone, M: Clone + Default,

Source

pub fn new(key: K, value: V) -> Self

Create a new cache entry with default metadata

Source§

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

Source

pub fn with_metadata(key: K, value: V, metadata: M) -> Self

Create a new cache entry with metadata

Source

pub fn with_ttl(self, ttl: Duration) -> Self

Set expiry time for the entry

Source

pub fn is_expired(&self) -> bool

Check if the entry has expired

Source

pub fn record_access(&mut self)

Update access statistics

Source

pub fn age(&self) -> Duration

Get the age of the entry

Trait Implementations§

Source§

impl<K, V, M> Clone for CacheEntry<K, V, M>
where K: Clone + Hash + Eq + Clone, V: Clone + Clone, M: Clone + Clone,

Source§

fn clone(&self) -> CacheEntry<K, V, M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, M> Debug for CacheEntry<K, V, M>
where K: Clone + Hash + Eq + Debug, V: Clone + Debug, M: Clone + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, K, V, M> Deserialize<'de> for CacheEntry<K, V, M>
where K: Clone + Hash + Eq + Deserialize<'de>, V: Clone + Deserialize<'de>, M: Clone + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, V, M> Searchable for CacheEntry<K, V, M>
where K: Clone + Hash + Eq + Display, V: Clone + Debug, M: Clone + EntryMetadata,

Implement Searchable for common types

Source§

type Query = SearchQuery

Query type for searching
Source§

fn matches(&self, query: &Self::Query) -> bool

Check if this entry matches the query
Source§

impl<K, V, M> Serialize for CacheEntry<K, V, M>
where K: Clone + Hash + Eq + Serialize, V: Clone + Serialize, M: Clone + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, V, M> Freeze for CacheEntry<K, V, M>
where K: Freeze, V: Freeze, M: Freeze,

§

impl<K, V, M> RefUnwindSafe for CacheEntry<K, V, M>

§

impl<K, V, M> Send for CacheEntry<K, V, M>
where K: Send, V: Send, M: Send,

§

impl<K, V, M> Sync for CacheEntry<K, V, M>
where K: Sync, V: Sync, M: Sync,

§

impl<K, V, M> Unpin for CacheEntry<K, V, M>
where K: Unpin, V: Unpin, M: Unpin,

§

impl<K, V, M> UnsafeUnpin for CacheEntry<K, V, M>

§

impl<K, V, M> UnwindSafe for CacheEntry<K, V, M>
where K: UnwindSafe, V: UnwindSafe, M: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,