stale
Adds stale-while-revalidate to the Cache-Control header. The CDN serves stale content while fetching a fresh response in the background. Requires cache — compilation error without it. Queries only.
Basic Usage
// Cache 5 min, serve stale for up to 1 hour while revalidating
#[rpc_query(cache = "5m", stale = "1h")]
async fn get_feed() -> Vec<Post> { ... }With Private Cache
// Private cache with stale-while-revalidate
#[rpc_query(cache = "private, 10m", stale = "30m")]
async fn get_dashboard() -> Dashboard { ... }Generated Headers
// cache = "5m", stale = "1h" produces:
// Cache-Control: public, max-age=300, stale-while-revalidate=3600
// cache = "private, 10m", stale = "30m" produces:
// Cache-Control: private, max-age=600, stale-while-revalidate=1800Requires cache
Using stale without cache is a compilation error.
// Compile error — stale requires cache
// #[rpc_query(stale = "1h")]
// async fn bad() -> Data { ... }Try it
Stale-While-Revalidate — 10s + 30s
Cache-Control: public, max-age=0, s-maxage=10, stale-while-revalidate=30
Cached for 10s, then serves stale for up to 30s while revalidating in the background.