Skip to main content

L1Cache

Struct L1Cache 

Source
pub struct L1Cache<S: CacheSource> { /* private fields */ }
Expand description

In-process L1 cache that fronts a CacheSource with a DashMap.

get serves fresh keys from memory and falls back to the wrapped store on a miss or once an entry’s TTL elapses, repopulating the cache on the way out (cache-aside). Concurrent misses for the same key collapse to a single load call (stampede protection), so a burst of cold lookups never fans out into N backend round-trips.

Implementations§

Source§

impl<S: CacheSource> L1Cache<S>

Source

pub fn new(inner: S, ttl: Duration) -> Self

Wrap inner, expiring cached entries ttl after insertion.

Source

pub fn inner(&self) -> &S

Borrow the wrapped store.

Source

pub fn len(&self) -> usize

Number of entries currently held (including any past their TTL but not yet evicted). Intended for diagnostics, not control flow.

Source

pub fn is_empty(&self) -> bool

Whether the cache holds no entries.

Source

pub fn clear(&self)

Drop every cached entry.

Source

pub fn invalidate(&self, key: &S::Key) -> bool

Drop the cached entry for key; returns whether one was present.

This is the hook the Epic C push-invalidation channel calls when the Gateway reports that an agent’s policy changed: the next get reloads from the source of truth rather than serving a stale entry.

Source

pub async fn get(&self, key: S::Key) -> Result<S::Value>

Fetch the value for key, serving from cache when fresh.

Cache-aside: a hit clones out of the DashMap; a miss (or an expired entry) loads from the wrapped store, populates the cache, and returns.

Stampede protection: the first caller to miss a key becomes the leader and performs the single load; concurrent callers become followers, wait on a shared Notify, then re-read the now-populated cache. The inner store therefore sees exactly one call per key per miss window.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for L1Cache<S>

§

impl<S> !UnwindSafe for L1Cache<S>

§

impl<S> Freeze for L1Cache<S>
where S: Freeze,

§

impl<S> Send for L1Cache<S>

§

impl<S> Sync for L1Cache<S>

§

impl<S> Unpin for L1Cache<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for L1Cache<S>
where S: UnsafeUnpin,

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

Source§

type Output = T

Should always be Self
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.