Skip to main content

ExtensionCacheStore

Struct ExtensionCacheStore 

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

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

Implementations§

§

impl ExtensionCacheStore

pub fn new() -> ExtensionCacheStore

Create an empty cache store with default limits.

§Examples
use tenferro_runtime::ExtensionCacheStore;

let store = ExtensionCacheStore::new();
assert_eq!(store.len(), 0);

pub fn with_limits(limits: ExtensionCacheLimits) -> ExtensionCacheStore

Create an empty cache store with explicit limits.

pub const fn limits(&self) -> ExtensionCacheLimits

Return the active cache limits.

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

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

pub fn len(&self) -> usize

Current entry count.

pub fn is_empty(&self) -> bool

Return whether the store contains no entries.

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.

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

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.

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.

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

Clear entries selected by selector.

pub fn clear(&mut self)

Clear every extension cache entry.

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

Return cache-style stats for entries selected by selector.

Trait Implementations§

§

impl Debug for ExtensionCacheStore

§

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

Formats the value using the given formatter. Read more
§

impl Default for ExtensionCacheStore

§

fn default() -> ExtensionCacheStore

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,