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 (
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 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>
Clone the segment into a new boxed instance. Required because
Box<dyn OutcomePipeline> cannot directly derive Clone.Auto Trait Implementations§
impl !RefUnwindSafe for CacheService
impl !Sync for CacheService
impl !UnwindSafe for CacheService
impl Freeze for CacheService
impl Send for CacheService
impl Unpin for CacheService
impl UnsafeUnpin for CacheService
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