pub struct FlattenCache { /* private fields */ }Expand description
A bounded, thread-safe flatten cache. Most callers want the process-wide
one behind flatten_cached; the type is public so a host can own a
separate instance with its own bounds.
Implementations§
Source§impl FlattenCache
impl FlattenCache
Sourcepub fn new(max_entries: usize, max_bytes: usize) -> Self
pub fn new(max_entries: usize, max_bytes: usize) -> Self
A cache holding at most max_entries flattens and max_bytes bytes.
Sourcepub fn get_or_flatten<F>(
&self,
key: FlattenKey,
flatten: F,
) -> Result<Arc<Vec<u8>>, XfaError>
pub fn get_or_flatten<F>( &self, key: FlattenKey, flatten: F, ) -> Result<Arc<Vec<u8>>, XfaError>
Return the cached flatten for key, or run flatten and store its
result. The closure runs without the lock held, so a slow flatten never
blocks other lookups; two threads missing on the same key both flatten
and the later store replaces the earlier one with identical bytes.
Sourcepub fn invalidate(&self, key: &FlattenKey) -> bool
pub fn invalidate(&self, key: &FlattenKey) -> bool
Drop the entry for key, if any. Returns whether one was removed.
Sourcepub fn stats(&self) -> FlattenCacheStats
pub fn stats(&self) -> FlattenCacheStats
Current counters.
Auto Trait Implementations§
impl !Freeze for FlattenCache
impl RefUnwindSafe for FlattenCache
impl Send for FlattenCache
impl Sync for FlattenCache
impl Unpin for FlattenCache
impl UnsafeUnpin for FlattenCache
impl UnwindSafe for FlattenCache
Blanket Implementations§
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<T> ErasedDestructor for Twhere
T: 'static,
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