Skip to main content

EdgeCache

Struct EdgeCache 

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

LRU + version + TTL cache. Cheap to clone via Arc.

Implementations§

Source§

impl EdgeCache

Source

pub fn new(max_entries: usize) -> Self

Source

pub fn epoch(&self) -> u64

This process’s per-boot epoch (home role: stamped into every broadcast invalidation + the subscribe hello frame).

Source

pub fn next_version(&self) -> u64

Mint a fresh logical version (home role: stamps read misses and write invalidations from one local clock).

Source

pub fn current_version(&self) -> u64

Current value of the local version counter, without minting. Strictly greater than every version this process has stamped.

Source

pub fn observe_home_version(&self, v: u64)

Record a version observed from the home (edge role: SSE invalidations + the hello frame carry the home’s clock). Edge reads are stamped with observed_home_version(), i.e. at the last home version — any later home write mints a strictly greater version, so its <= sweep always catches them.

Source

pub fn observed_home_version(&self) -> u64

Last home version observed (0 until the first event/hello). The edge-role read stamp.

Source

pub fn on_home_epoch(&self, epoch: u64) -> usize

Handle the home’s per-boot epoch carried by an event. Returns the number of entries flushed. 0 (legacy/absent) is ignored. First sighting just records the epoch; a CHANGE means the home restarted with a reset version clock — every cached stamp is from an incomparable clock, so flush everything and reset the observed-home clock (the same event’s observe_home_version re-syncs it).

Source

pub fn flush_all(&self) -> usize

Drop every entry. Bumps the invalidation counter BEFORE taking the map lock so in-flight epoch-gated stores are rejected (same ordering contract as invalidate). Returns the count dropped.

Source

pub fn should_cache(&self, version: u64) -> bool

Whether a home-role read stamped with version is still safe to cache. False once an invalidation with up_to_version >= version has been applied — the read may predate the write that triggered it. (Cheap unlocked fast-path; the authoritative re-check is insert_if_fresh.)

Source

pub fn invalidation_epoch(&self) -> u64

Monotonic count of invalidation events applied. Edge-role reads snapshot it before forwarding; insert_if_epoch re-checks it under the map lock, so a store whose flight overlapped ANY invalidation is skipped (table-agnostic and conservative — the next identical read simply re-stores).

Source

pub fn get(&self, key: &CacheKey) -> Option<Arc<CacheEntry>>

Look up a cache entry. Returns None on miss or expired TTL. Bumps the LRU on hit (O(1)); increments hit/miss counters either way. Expired entries are removed lazily here.

Source

pub fn insert(&self, key: CacheKey, entry: CacheEntry)

Insert / overwrite an entry. The LRU victim is auto-evicted when at capacity (O(1)). Prefer the race-checked variants on production store paths.

Source

pub fn insert_if_fresh(&self, key: CacheKey, entry: CacheEntry) -> bool

Home-role store: re-checks the invalidation high-water mark UNDER the map lock, closing the TOCTOU between an unlocked should_cache and the push (a concurrent invalidate bumps the hwm before taking this same lock, so either we see the bump here and skip, or our insert lands first and its sweep drops the entry). Returns whether the entry was stored.

Source

pub fn insert_if_epoch( &self, key: CacheKey, entry: CacheEntry, epoch: u64, ) -> bool

Edge-role store: entry stamps live in the home’s clock, so the hwm gate is inert (stamps == hwm right after every event). Instead the store is valid only if NO invalidation was applied since epoch was snapshotted (before the read was forwarded). Checked under the map lock — same ordering proof as insert_if_fresh (invalidate bumps the counter before locking). Returns whether the entry was stored.

Source

pub fn invalidate(&self, up_to_version: u64, tables: &[String]) -> usize

Drop every entry whose version <= up_to_version AND whose tables overlaps with tables (empty tables invalidates every entry meeting the version bound). Also raises the high-water mark consulted by should_cache and bumps the invalidation epoch — both BEFORE the map lock is taken, which the insert_if_* race checks rely on. Returns the count dropped.

Table-targeted sweeps walk only the keys registered under the written tables (reverse index) — O(matching entries). Only the empty-table wildcard falls back to a full scan.

Source

pub fn stats(&self) -> EdgeCacheStats

Source

pub fn insert_with(&self, key: CacheKey, entry: CacheEntry)

Test-only: deterministic insert with explicit version + TTL.

Trait Implementations§

Source§

impl Clone for EdgeCache

Source§

fn clone(&self) -> EdgeCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more