pub struct ThingsCache { /* private fields */ }Expand description
Main cache manager for Things 3 data with intelligent invalidation
Implementations§
Source§impl ThingsCache
impl ThingsCache
Sourcepub fn new(config: &CacheConfig) -> Self
pub fn new(config: &CacheConfig) -> Self
Create a new cache with the given configuration
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a new cache with default configuration
Sourcepub async fn get_projects<F, Fut>(
&self,
key: &str,
fetcher: F,
) -> Result<Vec<Project>>
pub async fn get_projects<F, Fut>( &self, key: &str, fetcher: F, ) -> Result<Vec<Project>>
Get projects from cache or fetch if not cached
§Errors
Returns an error if the fetcher function fails.
Sourcepub async fn get_search_results<F, Fut>(
&self,
key: &str,
fetcher: F,
) -> Result<Vec<Task>>
pub async fn get_search_results<F, Fut>( &self, key: &str, fetcher: F, ) -> Result<Vec<Task>>
Get search results from cache or fetch if not cached
§Errors
Returns an error if the fetcher function fails.
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Invalidate all caches
Sourcepub async fn invalidate(&self, key: &str)
pub async fn invalidate(&self, key: &str)
Invalidate specific cache entry
Sourcepub fn get_stats(&self) -> CacheStats
pub fn get_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset cache statistics
Sourcepub fn set_preloader(&self, preloader: Arc<dyn CachePreloader>)
pub fn set_preloader(&self, preloader: Arc<dyn CachePreloader>)
Register a preloader. Replaces any previously-registered preloader.
The preloader’s predict will be invoked after every get_* call,
and warm will be invoked by the warming-loop tick for queued keys.
Sourcepub fn clear_preloader(&self)
pub fn clear_preloader(&self)
Remove the registered preloader. Subsequent get_* calls and warming
ticks become no-ops with respect to predictive preloading.
Sourcepub fn add_to_warming(&self, key: String, priority: u32)
pub fn add_to_warming(&self, key: String, priority: u32)
Add entry to cache warming list
Sourcepub fn remove_from_warming(&self, key: &str)
pub fn remove_from_warming(&self, key: &str)
Remove entry from cache warming list
Sourcepub async fn invalidate_by_entity(
&self,
entity_type: &str,
entity_id: Option<&ThingsId>,
) -> usize
pub async fn invalidate_by_entity( &self, entity_type: &str, entity_id: Option<&ThingsId>, ) -> usize
Selectively invalidate cache entries whose dependencies match
(entity_type, entity_id). Returns the number of keys submitted for
eviction (moka eviction may complete asynchronously).
entity_id == None is a wildcard that matches any cached entry
depending on entity_type. Entries that do not depend on the mutated
entity are left untouched.
Sourcepub async fn invalidate_by_operation(&self, operation: &str) -> usize
pub async fn invalidate_by_operation(&self, operation: &str) -> usize
Selectively invalidate cache entries whose dependencies list operation
among their invalidating operations. Returns the number of keys submitted
for eviction (moka eviction may complete asynchronously).
Sourcepub fn get_warming_stats(&self) -> (usize, u32)
pub fn get_warming_stats(&self) -> (usize, u32)
Get cache warming statistics
Sourcepub fn stop_cache_warming(&mut self)
pub fn stop_cache_warming(&mut self)
Stop cache warming
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ThingsCache
impl !RefUnwindSafe for ThingsCache
impl Send for ThingsCache
impl Sync for ThingsCache
impl Unpin for ThingsCache
impl UnsafeUnpin for ThingsCache
impl !UnwindSafe for ThingsCache
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
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>
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>
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