Expand description
Client-side cache handler.
Cache wires CacheStorage + CachePolicy onto a trillium-client request
lifecycle. Feature-gated behind client.
§Position in the handler chain
Add Cache last in the handler tuple:
ⓘ
client.with_handler((Logger::new(), Cache::new(storage)));Reasons:
runruns in declared order; the cache should be the lastrunso it can short-circuit the network with a fresh hit.after_responseruns in reverse declared order; the cache should be the firstafter_responseso it can read the response body and replace it with a streaming tee before any other handler reads the (one-shot) network body.
§Streaming
On miss, the cache installs a streaming tee between the origin response body and the user — bytes flow to storage and the user concurrently. Trailers propagate to both. The cap on stored body size is enforced mid-stream; if exceeded, the cache write is aborted and the remainder of the body passes through unmodified.
Structs§
- Cache
- Cache handler. Mount on a
trillium_client::Clienttogether with aCacheStoragebackend.