pub struct QueryCache<K, V>{ /* private fields */ }Expand description
Thread-safe query cache with LRU eviction.
The QueryCache stores query results with a TTL (time-to-live)
and evicts oldest entries when the cache is full.
§Examples
use forgekit_core::cache::QueryCache;
use std::time::Duration;
let cache = QueryCache::<String, String>::new(100, Duration::from_secs(300));
// Insert a value
cache.insert("key".to_string(), "value".to_string()).await;
// Retrieve it
if let Some(value) = cache.get(&"key".to_string()).await {
println!("Cached: {}", value);
}Implementations§
Source§impl<K, V> QueryCache<K, V>
impl<K, V> QueryCache<K, V>
Sourcepub fn new(max_size: usize, ttl: Duration) -> Self
pub fn new(max_size: usize, ttl: Duration) -> Self
Creates a new query cache.
§Arguments
max_size- Maximum number of entries before evictionttl- Time-to-live for cache entries
Sourcepub async fn insert(&self, key: K, value: V)
pub async fn insert(&self, key: K, value: V)
Inserts a value into the cache.
If the cache is full, the oldest entry is evicted (FIFO).
§Arguments
key- The cache keyvalue- The value to cache
Sourcepub async fn invalidate(&self, key: &K)
pub async fn invalidate(&self, key: &K)
Trait Implementations§
Source§impl<K, V> Clone for QueryCache<K, V>
impl<K, V> Clone for QueryCache<K, V>
Source§fn clone(&self) -> QueryCache<K, V>
fn clone(&self) -> QueryCache<K, V>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<K, V> !RefUnwindSafe for QueryCache<K, V>
impl<K, V> !UnwindSafe for QueryCache<K, V>
impl<K, V> Freeze for QueryCache<K, V>
impl<K, V> Send for QueryCache<K, V>
impl<K, V> Sync for QueryCache<K, V>
impl<K, V> Unpin for QueryCache<K, V>
impl<K, V> UnsafeUnpin for QueryCache<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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