pub struct HybridArticleCache { /* private fields */ }Expand description
Hybrid article cache with memory and disk tiers
Uses foyer’s HybridCache for automatic memory→disk spillover.
Hot articles stay in memory, cold articles spill to disk.
Supports tier-aware TTL: entries from higher tier backends get longer TTLs.
Formula: effective_ttl = base_ttl * (2 ^ tier)
Note: Keys are stored as String (message ID without brackets) because
foyer requires keys to implement the Code trait for disk serialization.
Implementations§
Source§impl HybridArticleCache
impl HybridArticleCache
Sourcepub async fn new(config: HybridCacheConfig) -> Result<Self>
pub async fn new(config: HybridCacheConfig) -> Result<Self>
Create a new hybrid cache with the given configuration
This will create the disk cache directory if it doesn’t exist.
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, )
Insert or update an article in the cache
With WriteOnInsertion policy, articles are written to disk immediately
in a background task (non-blocking).
UPSERT SEMANTICS: Never overwrites a larger semantic payload with a smaller one. A cached full article (220/222 response) must not be replaced by STAT availability.
The tier is stored with the entry for tier-aware TTL calculation.
Sourcepub async fn record_missing(
&self,
message_id: MessageId<'_>,
backend_id: BackendId,
)
pub async fn record_missing( &self, message_id: MessageId<'_>, backend_id: BackendId, )
Record that a backend doesn’t have an article (430 response)
Sourcepub async fn record_has_status(
&self,
message_id: MessageId<'_>,
status_code: StatusCode,
backend: BackendId,
tier: CacheTier,
)
pub async fn record_has_status( &self, message_id: MessageId<'_>, status_code: StatusCode, backend: BackendId, tier: CacheTier, )
Record successful backend availability without storing response payload bytes.
Sourcepub fn stats(&self) -> HybridCacheStats
pub fn stats(&self) -> HybridCacheStats
Get cache statistics
Trait Implementations§
Source§impl CacheStatsProvider for HybridArticleCache
impl CacheStatsProvider for HybridArticleCache
Source§fn display_stats(&self) -> CacheDisplayStats
fn display_stats(&self) -> CacheDisplayStats
Auto Trait Implementations§
impl !Freeze for HybridArticleCache
impl !RefUnwindSafe for HybridArticleCache
impl !UnwindSafe for HybridArticleCache
impl Send for HybridArticleCache
impl Sync for HybridArticleCache
impl Unpin for HybridArticleCache
impl UnsafeUnpin for HybridArticleCache
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