ResponseCache

Struct ResponseCache 

Source
pub struct ResponseCache { /* private fields */ }
Expand description

The local response cache: opaque store + route epochs + the single-flight revalidation guard + the request-coalescing leader map. Owned by the DataPlane; survives reloads.

Implementations§

Source§

impl ResponseCache

Source

pub fn new(store: Arc<dyn CacheStore>) -> Self

Build over a specific backend (tests inject the plain in-memory store; the OSS gateway uses the moka backend).

Source

pub fn set_store(&self, store: Arc<dyn CacheStore>)

Swap the backing store (SCALE-04, #183). Called at startup when a Redis cache config is present and the license grants the redis_cache feature claim. The old store’s entries are NOT migrated (the new store starts cold; a two-tier CoordinatedCache fronts Redis with the local moka cache so hot keys survive).

Source

pub fn store_handle(&self) -> Arc<dyn CacheStore>

Clone of the backing store Arc (admin/metrics introspection seam).

Source

pub fn live_entries(&self) -> i64

Approximate live entries (the dwara_cache_entries gauge walk; 0 when the backend cannot report).

Source

pub fn purge_count(&self) -> u64

Purges + epoch bumps performed since process start.

Source

pub fn epoch(&self, route: &str) -> u64

The route’s current cache epoch (0 for never-bumped routes).

Source

pub fn bump_route(&self, route: &str) -> u64

Advance one route’s epoch (admin purge, DW-037). Every entry stored under an earlier epoch is unreachable from the next lookup — O(1), no store enumeration, which is the whole point.

Source

pub fn purge_all(&self, route_names: impl IntoIterator<Item = String>) -> usize

Purge every named route at once (admin purge-all): bumps each CURRENT route’s epoch (routes no longer in the config have no reachable entries). Returns how many routes were invalidated.

Source

pub async fn purge_by_tag(&self, tag: &str) -> usize

Purge every entry tagged with tag (DP-04). The tag’s keys are deleted from the store and the tag’s index entry is cleared. Returns the number of keys the tag mapped to (a tag with no entries, or one the gateway never saw, returns 0). Unlike the epoch-based route purge this is an O(keys-with-tag) store deletion — the tag index is the only place the opaque CacheStore seam exposes which keys carry a tag.

Source

pub async fn purge_by_url(&self, url: &str, prefix: bool) -> usize

Purge every entry whose request URL matches (DP-04). With prefix false the URL must match exactly (path[?query]); with prefix true every URL whose path starts with prefix as a path segment is purged (e.g. /api/users/ evicts every user entry; /api/users evicts /api/users, /api/users/123, and /api/users?x=1 but NOT /api/users2). Returns the number of keys deleted. The URL index maps one URL to many keys (the cache key also folds the route epoch, the consumer, and the vary values), so a single URL purge can delete several entries.

Source

pub fn note_generation(&self, old: Option<&Snapshot>, fresh: &Snapshot)

Generation-change invalidation (called from DataPlane::refresh before the swap): a route whose definition CHANGED (Route equality — masking, transforms, the cache block itself, anything) has its epoch bumped, because its stored bytes were shaped by the old definition. Unchanged routes keep their entries warm; removed routes bump once so a later same-name re-add cannot inherit them.

Source

pub async fn lookup( self: &Arc<Self>, dp: &Arc<DataPlane>, policy: &Arc<CompiledRouteCache>, route: &Route, identity: Option<&Identity>, peer: IpAddr, path: &str, query: Option<&str>, req_headers: &HeaderMap, method: &Method, declared_body_bytes: Option<u64>, obs: &Observability, ) -> LookupOutcome

The lookup half of the cache (DW-037), running after authn/ authz/rate limiting/admission and before the proxy action. See the module docs for the cacheability rules and the key derivation; this function only classifies and either replays or hands a MissFlow to the store stage.

Source

pub async fn store_stage( &self, flow: CacheFlow, resp: Response<ProxyBody>, rid: &str, obs: &Observability, ) -> Response<ProxyBody>

The store half of the cache (DW-037), running after masking and the DW-028 transforms and before compression. Stamps the x-cache outcome on the response in every arm. See the module docs for the response-side storable rules.

Source

pub async fn attach( &self, flow: &MissFlow, obs: &Observability, ) -> CoalesceOutcome

Request coalescing (DW-038): resolve ONE cache miss into the leader, a served follower, or an independent fetch. The coalescing key is the cache key itself (route epoch, consumer, path, query, vary — see derive_key), so a follower can only be handed an outcome computed for an identical request shape of its own consumer and generation. The caller runs its fetch on Lead/Solo and drops the guard when its store stage is done.

Follower resolution, in the pinned order: (1) wait, bounded by the route’s coalescing.wait_ms; (2) epoch check FIRST — a mid-flight purge/config change detours to an independent fetch even if the leader stored something; (3) store re-read — a live entry replays exactly like a hit; (4) otherwise an independent fetch (leader finished unstored, or the wait expired). Every fallback is the caller’s NORMAL miss path: failures are never inherited, and each fetching follower runs the route’s full retry policy.

Trait Implementations§

Source§

impl Default for ResponseCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyExt for T
where T: Any + ?Sized,

§

fn downcast_ref<T>(this: &Self) -> Option<&T>
where T: Any,

Attempts to downcast this to T behind reference
§

fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>
where T: Any,

Attempts to downcast this to T behind mutable reference
§

fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Any,

Attempts to downcast this to T behind Rc pointer
§

fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Any,

Attempts to downcast this to T behind Arc pointer
§

fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Any,

Attempts to downcast this to T behind Box pointer
§

fn downcast_move<T>(this: Self) -> Option<T>
where T: Any, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

§

fn coerce_box_to(self: Box<X>) -> Box<T>

§

fn coerce_ref_to(&self) -> &T

§

fn coerce_mut_to(&mut self) -> &mut T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,