response-cache
Cache GET 200 responses in KvStore
| Crate | sova-response-cache 0.1.1 |
| Plugin id | response-cache |
| Category | HTTP |
Install
bash
cargo add sova --features response-cacheFeatures
| Feature | What you get |
|---|---|
response-cache | Cache public GET 200 responses in KvStore. |
Overview
When: cache public GET 200 responses (lists, marketing pages).
Does:
- Skips requests with
Authorization/Cookieunlesscache_private(true) - Key = method + path + sorted
Varyheaders - Sets
X-Cache: HIT|MISSandCache-Control - Invalidate via
ResponseCacheHandle::invalidate_prefix(e.g. from anEventBuslistener)
Example
rust
use std::sync::Arc;
use std::time::Duration;
use sova::{Memory, ResponseCache};
let store = Arc::new(Memory::new());
app.install(ResponseCache::new(store).ttl(Duration::from_secs(60)).vary(&["accept-language"]));Notes
- Feature
response-cache(+store) - Does not replace static file ETag — dynamic routes only
Quick start
rust
use sova::store::Memory;
use sova::ResponseCache;
use std::sync::Arc;
app.install(ResponseCache::new(Arc::new(Memory::new())));
// From a handler / event listener:
// req.state::<ResponseCacheHandle>().invalidate_prefix("/api/notes").await;