pub struct MemoryCache { /* private fields */ }Expand description
In-memory LRU cache for fetch and search results.
Thread-safe and async-native via moka. Each entry has a TTL
and the total number of entries is bounded.
Implementations§
Source§impl MemoryCache
impl MemoryCache
Sourcepub fn new(max_entries: u64, ttl_secs: u64, enabled: bool) -> Self
pub fn new(max_entries: u64, ttl_secs: u64, enabled: bool) -> Self
Create a new memory cache with the given configuration.
Sourcepub fn from_config(config: &CacheConfig) -> Self
pub fn from_config(config: &CacheConfig) -> Self
Create a cache with default settings from config.
Sourcepub async fn get<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
pub async fn get<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
Get a cached value by key, if it exists and has not expired.
Sourcepub async fn set<T: Serialize>(&self, key: &str, value: &T)
pub async fn set<T: Serialize>(&self, key: &str, value: &T)
Store a value in the cache under the given key.
If the serialized value exceeds MAX_ENTRY_BYTES, the entry is silently skipped to prevent memory bloat from large pages.
Sourcepub async fn invalidate(&self, key: &str)
pub async fn invalidate(&self, key: &str)
Remove a specific entry from the cache.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Return cache statistics.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether the cache is enabled.
Trait Implementations§
Source§impl Clone for MemoryCache
impl Clone for MemoryCache
Auto Trait Implementations§
impl !RefUnwindSafe for MemoryCache
impl !UnwindSafe for MemoryCache
impl Freeze for MemoryCache
impl Send for MemoryCache
impl Sync for MemoryCache
impl Unpin for MemoryCache
impl UnsafeUnpin for MemoryCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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