pub struct Cache<B, CM = NoopConcurrencyManager, O = DisabledOffload> { /* private fields */ }Expand description
Pre-configured cache with backend, policy, concurrency manager, and offload manager.
Use Cache::builder() to create a new cache configuration.
§Example
ⓘ
use hitbox_fn::Cache;
use hitbox::policy::PolicyConfig;
use hitbox_moka::MokaBackend;
use std::time::Duration;
let backend = MokaBackend::builder().max_entries(1000).build();
let policy = PolicyConfig::builder().ttl(Duration::from_secs(60)).build();
let cache = Cache::builder()
.backend(backend)
.policy(policy)
.build();
// Use with cached functions
let result = my_cached_function(arg1, arg2)
.cache(&cache)
.await;
// With offload manager for Stale-While-Revalidate
use hitbox::offload::OffloadManager;
let cache = Cache::builder()
.backend(backend)
.policy(policy)
.offload(OffloadManager::with_defaults())
.build();Implementations§
Source§impl<B, CM, O> Cache<B, CM, O>
impl<B, CM, O> Cache<B, CM, O>
Sourcepub fn policy(&self) -> &Arc<PolicyConfig>
pub fn policy(&self) -> &Arc<PolicyConfig>
Get a reference to the policy Arc.
Sourcepub fn concurrency_manager(&self) -> &CM
pub fn concurrency_manager(&self) -> &CM
Get a reference to the concurrency manager.
Source§impl Cache<(), NoopConcurrencyManager, DisabledOffload>
impl Cache<(), NoopConcurrencyManager, DisabledOffload>
Sourcepub fn builder() -> CacheBuilder<NoBackend, NoPolicy, NoopConcurrencyManager, DisabledOffload>
pub fn builder() -> CacheBuilder<NoBackend, NoPolicy, NoopConcurrencyManager, DisabledOffload>
Create a new cache builder.
Trait Implementations§
Source§impl<B, CM: Clone, O: Clone> CacheAccess for Cache<B, CM, O>
impl<B, CM: Clone, O: Clone> CacheAccess for Cache<B, CM, O>
Source§type ConcurrencyManager = CM
type ConcurrencyManager = CM
The concurrency manager type.
Source§fn policy(&self) -> Arc<PolicyConfig>
fn policy(&self) -> Arc<PolicyConfig>
Get a shared reference to the policy.
Source§fn concurrency_manager(&self) -> CM
fn concurrency_manager(&self) -> CM
Get the concurrency manager.
Auto Trait Implementations§
impl<B, CM, O> Freeze for Cache<B, CM, O>
impl<B, CM, O> RefUnwindSafe for Cache<B, CM, O>
impl<B, CM, O> Send for Cache<B, CM, O>
impl<B, CM, O> Sync for Cache<B, CM, O>
impl<B, CM, O> Unpin for Cache<B, CM, O>
impl<B, CM, O> UnsafeUnpin for Cache<B, CM, O>where
CM: UnsafeUnpin,
O: UnsafeUnpin,
impl<B, CM, O> UnwindSafe for Cache<B, CM, O>
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> CachedFieldClone for Twhere
T: Clone,
impl<T> CachedFieldClone for Twhere
T: Clone,
Source§fn cached_clone(&self) -> T
fn cached_clone(&self) -> T
Clone this field for cache storage.