pub struct RevisionCache<T> { /* private fields */ }Expand description
Memoizes a value T by a monotonically-advancing revision, rebuilding via build
only when the supplied revision exceeds the cached one.
Uses a dedicated single-flight build_lock alongside the RwLock storage so:
- Concurrent callers requesting a newer revision coalesce into a single
build()invocation instead of triggering an $N$-thread rebuild stampede. - Existing readers can continue reading the previous snapshot while the new revision is being built, blocking only for the $O(1)$ pointer swap.
- Monotonic revision checks prevent a stale revision from overwriting a newer one.
Implementations§
Source§impl<T> RevisionCache<T>
impl<T> RevisionCache<T>
Sourcepub fn current_revision(&self) -> Option<u64>
pub fn current_revision(&self) -> Option<u64>
Returns the currently cached revision, or None if the cache is empty.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Clears the cached value so the next Self::with call rebuilds it.
Sourcepub fn with<R>(
&self,
revision: u64,
build: impl FnOnce() -> T,
f: impl FnOnce(&T) -> R,
) -> R
pub fn with<R>( &self, revision: u64, build: impl FnOnce() -> T, f: impl FnOnce(&T) -> R, ) -> R
Run f against the value cached at revision (or newer), building it via build
first if the cache is empty or at a lower revision. build runs at most once per
distinct monotonic revision advance, and only when a caller actually needs the value.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for RevisionCache<T>
impl<T> RefUnwindSafe for RevisionCache<T>
impl<T> Send for RevisionCache<T>where
T: Send,
impl<T> Sync for RevisionCache<T>
impl<T> Unpin for RevisionCache<T>where
T: Unpin,
impl<T> UnsafeUnpin for RevisionCache<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for RevisionCache<T>
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Aggregate shares in an MPC protocol.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.