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. cache_size, sweep_interval, and
stale_retention are retained so the propagation seam required by the
eip-cache spec can expose them via accessors.
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>,
cache_size: 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>, cache_size: 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.
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Recorded redb page-cache size in bytes (propagation seam for the eip-cache spec).
Sourcepub fn sweep_interval(&self) -> Duration
pub fn sweep_interval(&self) -> Duration
Recorded background-sweep interval.
Sourcepub fn stale_retention(&self) -> Duration
pub fn stale_retention(&self) -> Duration
Recorded stale-retention window.
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 invalidate_prefix<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn invalidate_prefix<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64, CamelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove every entry whose key starts with
prefix, returning the removed count. Read moreSource§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<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Return current cache statistics. Asynchronous so backends can offload
I/O-bound byte accounting off the tokio worker (bd rc-22wj). Default
implementation returns zeroed stats.
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