pub trait Cache<K: Eq + Hash, V: Clone>: Send + Sync {
// Required methods
fn get(&self, key: &K) -> Option<V>;
fn insert(&self, key: K, value: V) -> Option<V>;
fn invalidate(&self, key: &K);
fn clear(&self);
fn size(&self) -> u64;
}Expand description
A generic key-value cache with thread-safe operations.
Implementations must be Send + Sync so they can be shared
across async tasks and stored in an Arc.
§Examples
use vlorql_core::cache::{Cache, NoopCache};
let cache = NoopCache::<u64, String>::new();
assert!(cache.get(&42).is_none());
cache.insert(42, "hello".to_owned());
assert_eq!(cache.size(), 0); // NoopCache never stores anythingRequired Methods§
Sourcefn insert(&self, key: K, value: V) -> Option<V>
fn insert(&self, key: K, value: V) -> Option<V>
Inserts a value into the cache.
Returns the previous value associated with the key, if any.
Sourcefn invalidate(&self, key: &K)
fn invalidate(&self, key: &K)
Removes the entry for key from the cache.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".