Skip to main content

Module client

Module client 

Source
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:

  • run runs in declared order; the cache should be the last run so it can short-circuit the network with a fresh hit.
  • after_response runs in reverse declared order; the cache should be the first after_response so 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::Client together with a CacheStorage backend.