pub trait Cache<K: CacheKey, V: CacheValue>: Send + Sync {
Show 14 methods
// Required methods
fn get(&self, key: &K) -> Option<V>;
fn put(&self, key: &K, value: V) -> Option<V>;
fn remove(&self, k: &K) -> Option<V>;
fn contains_key(&self, k: &K) -> bool;
fn len(&self) -> usize;
fn clear(&self);
fn name(&self) -> String;
fn cache_limit(&self) -> usize;
fn update_cache_limit(&self, limit: usize);
fn cache_ttl(&self) -> Option<Duration>;
fn update_cache_ttl(&self, _ttl: Option<Duration>);
fn drop_table_entries(&self, table_ref: &TableReference) -> Result<()>;
fn list_entries(&self) -> HashMap<K, CacheEntryInfo<V>>;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
Base trait for cache implementations with common operations.
This trait provides the fundamental cache operations (get, put, remove, etc.)
that all cache types share.
§Thread Safety
Implementations must handle their own locking via internal mutability, as methods do not take mutable references and may be accessed by multiple concurrent queries.
Required Methods§
Sourcefn put(&self, key: &K, value: V) -> Option<V>
fn put(&self, key: &K, value: V) -> Option<V>
Store a value in the cache.
Returns the previous value if one existed.
Sourcefn remove(&self, k: &K) -> Option<V>
fn remove(&self, k: &K) -> Option<V>
Remove an entry from the cache, returning the value if it existed.
Sourcefn contains_key(&self, k: &K) -> bool
fn contains_key(&self, k: &K) -> bool
Check if the cache contains a specific key.
Sourcefn cache_limit(&self) -> usize
fn cache_limit(&self) -> usize
Current memory budget, in bytes.
Sourcefn update_cache_limit(&self, limit: usize)
fn update_cache_limit(&self, limit: usize)
Change the memory budget in bytes.
Sourcefn cache_ttl(&self) -> Option<Duration>
fn cache_ttl(&self) -> Option<Duration>
Time-to-live applied to newly inserted entries, or None if entries
never expire on their own.
Sourcefn update_cache_ttl(&self, _ttl: Option<Duration>)
fn update_cache_ttl(&self, _ttl: Option<Duration>)
Change the TTL applied to subsequent inserts.
Sourcefn drop_table_entries(&self, table_ref: &TableReference) -> Result<()>
fn drop_table_entries(&self, table_ref: &TableReference) -> Result<()>
Invalidate every entry associated with table_ref.
Sourcefn list_entries(&self) -> HashMap<K, CacheEntryInfo<V>>
fn list_entries(&self) -> HashMap<K, CacheEntryInfo<V>>
Snapshot of all current entries with per-entry metadata (size, hits, expiration) for diagnostics and observability.
Provided Methods§
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".