Skip to main content

Module cache

Module cache 

Source
Expand description

Per-route response cache, driven by #[CacheTTL(N)] on the route method.

Implemented as a singleton Interceptor whose around reads the matched route’s RouteSpec.cache_ttl_secs. If the TTL is non-zero the interceptor consults a process-global, sharded, lock-striped store (dashmap) keyed by method + path + query. On hit, the cached body bytes are replayed — the inner handler is never invoked. On miss, the inner chain runs and the 2xx response body is fingerprinted and stored.

Why dashmap rather than a single RwLock<HashMap>: read concurrency in dashmap is per-shard — a hot cached endpoint serializes only against the small minority of requests targeting the same shard. There is no single global lock on the request path. Writes touch one shard.

Why not lock-free? papaya/seize-style stores would be truly lock-free but add a non-trivial dependency footprint. dashmap is the standard pragmatic choice and matches the audit’s “no global lock on the active request path” intent.

Structs§

CacheInterceptor
The interceptor itself — a unit struct so it can be referenced from a static in macro-generated code (see wrap_interceptors in the macros crate).
CacheStats
Telemetry snapshot for the cache. Plugins / handlers can expose this.

Functions§

clear
Manually invalidate all cached entries. Useful for tests + admin endpoints.
stats