pub struct RedbCacheRepository { /* private fields */ }Expand description
Redb-backed implementation of CacheRepository.
All counters are Arc<AtomicU64> so the spawned sweep task can update
them via cloned references. sweep_interval is consumed by the
constructor to build the ticker and is not stored.
Implementations§
Source§impl RedbCacheRepository
impl RedbCacheRepository
Sourcepub async fn new(
name: impl Into<String>,
path: impl Into<PathBuf>,
stale_retention: Duration,
max_entries: Option<usize>,
sweep_interval: Duration,
shutdown_token: CancellationToken,
) -> Result<Self, CamelError>
pub async fn new( name: impl Into<String>, path: impl Into<PathBuf>, stale_retention: Duration, max_entries: Option<usize>, sweep_interval: Duration, shutdown_token: CancellationToken, ) -> Result<Self, CamelError>
Open (or create) the redb database at path, seed the entries
counter from table.len(), and spawn the background sweep task.
shutdown_token is the context’s token — binding the sweep to
context shutdown. The whole open sequence runs in
spawn_blocking because redb::Database::create is blocking.
Trait Implementations§
Source§impl CacheRepository for RedbCacheRepository
impl CacheRepository for RedbCacheRepository
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve a value by key. Read more
Source§fn set<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: CacheEntry,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: CacheEntry,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store a value with an optional TTL. Read more
Source§fn peek_stale<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn peek_stale<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Peek at a stale (expired but not yet evicted) entry. Read more
Source§fn invalidate<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn invalidate<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove a specific key from the cache.
Source§fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Remove all entries from the cache.
Source§fn stats(&self) -> CacheStats
fn stats(&self) -> CacheStats
Return current cache statistics. Read more
Source§impl Debug for RedbCacheRepository
impl Debug for RedbCacheRepository
Source§impl Drop for RedbCacheRepository
impl Drop for RedbCacheRepository
Auto Trait Implementations§
impl !Freeze for RedbCacheRepository
impl !RefUnwindSafe for RedbCacheRepository
impl !UnwindSafe for RedbCacheRepository
impl Send for RedbCacheRepository
impl Sync for RedbCacheRepository
impl Unpin for RedbCacheRepository
impl UnsafeUnpin for RedbCacheRepository
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