Skip to main content

ExtensionCacheStore

Struct ExtensionCacheStore 

Source
pub struct ExtensionCacheStore { /* private fields */ }
Expand description

Bounded type-erased cache storage owned by an extension executor.

Implementations§

Source§

impl ExtensionCacheStore

Source

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);
Source

pub fn with_limits(limits: ExtensionCacheLimits) -> Self

Create an empty cache store with explicit limits.

Source

pub const fn limits(&self) -> ExtensionCacheLimits

Return the active cache limits.

Source

pub fn set_limits(&mut self, limits: ExtensionCacheLimits)

Resize the store and evict least-recently-used entries if needed.

Source

pub fn len(&self) -> usize

Current entry count.

Source

pub fn is_empty(&self) -> bool

Return whether the store contains no entries.

Source

pub fn put<T>( &mut self, key: ExtensionCacheKey, value: T, retained_bytes: usize, )
where T: Any + Send + Sync + 'static,

Insert or replace a typed cache entry.

Source

pub fn put_with_retained_bytes<T, F>( &mut self, key: ExtensionCacheKey, value: T, retained_bytes: F, )
where T: Any + Send + Sync + 'static, F: Fn(&T) -> usize + Send + Sync + 'static,

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>()
);
Source

pub fn get<T>(&mut self, key: &ExtensionCacheKey) -> Option<&T>
where T: Any + Send + Sync + 'static,

Get a typed cache entry, updating its LRU position.

Source

pub fn get_mut<T>(&mut self, key: &ExtensionCacheKey) -> Option<&mut T>
where T: Any + Send + Sync + 'static,

Get a mutable typed cache entry, updating its LRU position.

Source

pub fn clear_selected(&mut self, selector: ExtensionCacheSelector)

Clear entries selected by selector.

Source

pub fn clear(&mut self)

Clear every extension cache entry.

Source

pub fn stats(&self, selector: ExtensionCacheSelector) -> CacheStats

Return cache-style stats for entries selected by selector.

Trait Implementations§

Source§

impl Debug for ExtensionCacheStore

Source§

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

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

impl Default for ExtensionCacheStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, 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.