pub struct ExtensionCacheStore { /* private fields */ }Expand description
Bounded type-erased cache storage owned by an extension executor.
Implementations§
Source§impl ExtensionCacheStore
impl ExtensionCacheStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty cache store with default limits.
§Examples
use tenferro_runtime::ExtensionCacheStore;
let store = ExtensionCacheStore::new();
assert_eq!(store.len(), 0);Sourcepub fn with_limits(limits: ExtensionCacheLimits) -> Self
pub fn with_limits(limits: ExtensionCacheLimits) -> Self
Create an empty cache store with explicit limits.
Sourcepub const fn limits(&self) -> ExtensionCacheLimits
pub const fn limits(&self) -> ExtensionCacheLimits
Return the active cache limits.
Sourcepub fn set_limits(&mut self, limits: ExtensionCacheLimits)
pub fn set_limits(&mut self, limits: ExtensionCacheLimits)
Resize the store and evict least-recently-used entries if needed.
Sourcepub fn put<T>(
&mut self,
key: ExtensionCacheKey,
value: T,
retained_bytes: usize,
)
pub fn put<T>( &mut self, key: ExtensionCacheKey, value: T, retained_bytes: usize, )
Insert or replace a typed cache entry.
Sourcepub fn put_with_retained_bytes<T, F>(
&mut self,
key: ExtensionCacheKey,
value: T,
retained_bytes: F,
)
pub fn put_with_retained_bytes<T, F>( &mut self, key: ExtensionCacheKey, value: T, retained_bytes: F, )
Insert or replace a typed cache entry whose retained bytes are computed from the current value whenever stats are requested.
Use this for entries that mutate after insertion, such as compiled execution plans with backend-owned nested caches.
§Examples
use tenferro_runtime::{ExtensionCacheKey, ExtensionCacheStore, ExtensionCacheSelector};
let mut store = ExtensionCacheStore::new();
let key = ExtensionCacheKey::new("example.cache.v1", "plans", 0);
store.put_with_retained_bytes(key, Vec::<usize>::with_capacity(2), |values| {
values.capacity().saturating_mul(std::mem::size_of::<usize>())
});
let values = store.get_mut::<Vec<usize>>(&key).unwrap();
values.reserve_exact(4);
let retained_capacity = values.capacity();
assert_eq!(
store.stats(ExtensionCacheSelector::All).retained_bytes,
retained_capacity * std::mem::size_of::<usize>()
);Sourcepub fn get<T>(&mut self, key: &ExtensionCacheKey) -> Option<&T>
pub fn get<T>(&mut self, key: &ExtensionCacheKey) -> Option<&T>
Get a typed cache entry, updating its LRU position.
Sourcepub fn get_mut<T>(&mut self, key: &ExtensionCacheKey) -> Option<&mut T>
pub fn get_mut<T>(&mut self, key: &ExtensionCacheKey) -> Option<&mut T>
Get a mutable typed cache entry, updating its LRU position.
Sourcepub fn clear_selected(&mut self, selector: ExtensionCacheSelector)
pub fn clear_selected(&mut self, selector: ExtensionCacheSelector)
Clear entries selected by selector.
Sourcepub fn stats(&self, selector: ExtensionCacheSelector) -> CacheStats
pub fn stats(&self, selector: ExtensionCacheSelector) -> CacheStats
Return cache-style stats for entries selected by selector.
Trait Implementations§
Source§impl Debug for ExtensionCacheStore
impl Debug for ExtensionCacheStore
Auto Trait Implementations§
impl Freeze for ExtensionCacheStore
impl !RefUnwindSafe for ExtensionCacheStore
impl Send for ExtensionCacheStore
impl Sync for ExtensionCacheStore
impl Unpin for ExtensionCacheStore
impl UnsafeUnpin for ExtensionCacheStore
impl !UnwindSafe for ExtensionCacheStore
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