pub enum UnifiedCache {
Availability(AvailabilityIndex),
Memory(ArticleCache),
Hybrid(HybridArticleCache),
}Expand description
Unified cache that can be availability-only, memory-only (moka), or hybrid (foyer)
This enum provides a common interface for all cache implementations, allowing the proxy to switch between availability-only, memory, and disk-backed caching based on configuration.
Variants§
Availability(AvailabilityIndex)
Availability-only negative index with exact key matches.
Memory(ArticleCache)
Memory-only cache using moka
Hybrid(HybridArticleCache)
Hybrid memory+disk cache using foyer
Implementations§
Source§impl UnifiedCache
impl UnifiedCache
Sourcepub fn availability(ttl: Duration) -> Self
pub fn availability(ttl: Duration) -> Self
Create an availability-only negative index.
Sourcepub async fn hybrid(config: HybridCacheConfig) -> Result<Self>
pub async fn hybrid(config: HybridCacheConfig) -> Result<Self>
Create a hybrid cache (async because foyer needs async initialization)
Sourcepub const fn records_backend_has_status(&self) -> bool
pub const fn records_backend_has_status(&self) -> bool
Returns true when successful backend responses update positive availability metadata.
Sourcepub const fn stores_payload_responses(&self) -> bool
pub const fn stores_payload_responses(&self) -> bool
Returns true when this cache stores response payloads.
Sourcepub async fn get(&self, message_id: &MessageId<'_>) -> Option<CachedArticle>
pub async fn get(&self, message_id: &MessageId<'_>) -> Option<CachedArticle>
Get an article from the cache
Sourcepub async fn get_request_message_id(
&self,
message_id: &str,
) -> Option<CachedArticle>
pub async fn get_request_message_id( &self, message_id: &str, ) -> Option<CachedArticle>
Get an article from a validated request message-id string (<...>).
Memory and hybrid cache hits avoid rebuilding a MessageId by looking up
the stripped cache key directly.
Sourcepub async fn upsert_ingest(
&self,
message_id: MessageId<'_>,
buffer: impl Into<CacheIngestResponse>,
backend: BackendId,
tier: CacheTier,
)
pub async fn upsert_ingest( &self, message_id: MessageId<'_>, buffer: impl Into<CacheIngestResponse>, backend: BackendId, tier: CacheTier, )
Store a successful article response for an eligible backend.
Sourcepub async fn record_backend_missing(
&self,
message_id: MessageId<'_>,
backend_id: BackendId,
)
pub async fn record_backend_missing( &self, message_id: MessageId<'_>, backend_id: BackendId, )
Record that a backend returned 430 for this article
Sourcepub async fn record_backend_has_status(
&self,
message_id: MessageId<'_>,
status_code: StatusCode,
backend: BackendId,
tier: CacheTier,
)
pub async fn record_backend_has_status( &self, message_id: MessageId<'_>, status_code: StatusCode, backend: BackendId, tier: CacheTier, )
Record that a backend has an article with a known status, without storing payload bytes.
Sourcepub fn load_from_disk(&self, path: &Path) -> Result<bool>
pub fn load_from_disk(&self, path: &Path) -> Result<bool>
Load persisted availability state if this is an availability-only cache.
Sourcepub fn save_to_disk(&self, path: &Path) -> Result<bool>
pub fn save_to_disk(&self, path: &Path) -> Result<bool>
Save persisted availability state if this is an availability-only cache.
Sourcepub fn entry_count(&self) -> u64
pub fn entry_count(&self) -> u64
Get number of cached entries
Sourcepub fn weighted_size(&self) -> u64
pub fn weighted_size(&self) -> u64
Get weighted size in bytes
Sourcepub const fn is_availability_only(&self) -> bool
pub const fn is_availability_only(&self) -> bool
Check if this cache is the dedicated availability-only index.
Trait Implementations§
Source§impl CacheStatsProvider for UnifiedCache
impl CacheStatsProvider for UnifiedCache
Source§fn display_stats(&self) -> CacheDisplayStats
fn display_stats(&self) -> CacheDisplayStats
Auto Trait Implementations§
impl !Freeze for UnifiedCache
impl !RefUnwindSafe for UnifiedCache
impl !UnwindSafe for UnifiedCache
impl Send for UnifiedCache
impl Sync for UnifiedCache
impl Unpin for UnifiedCache
impl UnsafeUnpin for UnifiedCache
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