Expand description
In-memory response cache middleware.
CacheLayer implements Middleware and short-circuits the inner
application for cacheable GET responses within their TTL. Entries are
bounded by a configurable capacity; the oldest entry is evicted when the
store is full and no expired entries remain.
§What is cached
- Method: GET only; all other methods bypass the cache.
- Status: 2xx responses (200, 201, 203, 204, 206, …).
- Response
Cache-Control: no-storeorprivate— not cached. - Request
Cache-Control: no-cache— cache is bypassed, handler is called, but the fresh response is stored (revalidation).
§Example
use rust_web_server::app::App;
use rust_web_server::cache::CacheLayer;
use rust_web_server::core::New;
let app = App::new()
.wrap(CacheLayer::memory(1000).ttl(60).vary_by_header("Accept"));Structs§
- Cache
Layer - An in-memory response cache middleware.