pub struct CacheService { /* private fields */ }Expand description
Outcome-aware Cache segment (Caching EIP).
Wraps a named CacheRepository and an on-miss sub-pipeline
(OutcomeSegment). On each exchange:
- Evaluate
key_expr.None→ not cacheable; forward directly to the on-miss sub-pipeline (no lookup, no write-back). repository.get(&key):Err(e)→Failed(e)(contract C1).Ok(Some(entry))→ HIT: reconstructBodyfrom the entry, set it on the exchange, returnCompleted(skip on-miss).Ok(None)→ MISS: proceed to step 3.
- Run the on-miss sub-pipeline.
Stopped(ex)/Failed(e)→ propagate as-is (NO write-back).Completed(ex)→ proceed to write-back.
- Write-back the resulting body (when it fits
max_entry_bytes):- materialized variants (
Bytes/Text/Json/Xml) → serialize, store. Stream→ materialize viaBody::into_bytes(consumes the body, replaces it withBody::Bytes);StreamLimitExceededpropagates.Empty/ oversized body → pass through uncached, returnCompleted.
- materialized variants (
With coalesce_misses enabled (CacheService::with_coalesce),
concurrent misses on the same resolved key are coalesced
(singleflight): the first exchange (leader) runs on_miss and the
single write-back set; concurrent exchanges (waiters) await the
leader’s terminal state instead of running on_miss. HIT, key-None,
and coalesce_misses == false paths bypass the in-flight map
entirely.
Implementations§
Source§impl CacheService
impl CacheService
Sourcepub fn new(
repository: Arc<dyn CacheRepository>,
key_expr: MessageIdExpression,
ttl: Option<Duration>,
max_entry_bytes: usize,
on_miss: OutcomeSegment,
rt: Arc<dyn RuntimeObservability>,
) -> Self
pub fn new( repository: Arc<dyn CacheRepository>, key_expr: MessageIdExpression, ttl: Option<Duration>, max_entry_bytes: usize, on_miss: OutcomeSegment, rt: Arc<dyn RuntimeObservability>, ) -> Self
Build a new cache segment.
repository_name is derived from repository.name() so OTel tags stay
in sync with the resolved backend.
Sourcepub fn with_coalesce(self, coalesce_misses: bool) -> Self
pub fn with_coalesce(self, coalesce_misses: bool) -> Self
Enable (or explicitly disable) singleflight miss coalescing.
With coalescing on, concurrent misses on the same resolved key
run the on_miss sub-pipeline exactly once per wave (leader
runs + writes back; waiters receive the leader’s terminal state).
Sourcepub fn repository_name(&self) -> &str
pub fn repository_name(&self) -> &str
The configured repository name (for OTel tagging).
Trait Implementations§
Source§impl Clone for CacheService
impl Clone for CacheService
Source§impl OutcomePipeline for CacheService
impl OutcomePipeline for CacheService
Source§fn clone_box(&self) -> Box<dyn OutcomePipeline>
fn clone_box(&self) -> Box<dyn OutcomePipeline>
Box<dyn OutcomePipeline> cannot directly derive Clone.