Caching

Set Cache-Control headers on #[load] responses to cache server data at the edge or in the browser.

cache attribute

#[load(cache = "public, max-age=60")]
async fn home(_req: &FlowRequest) -> HomeData {
    HomeData { title: "Welcome".into() }
}

#[load(cache = "public, max-age=120")]
async fn docs_index(_req: &FlowRequest) -> DocsData {
    fetch_docs().await
}

How it works

The cache string is applied as a Cache-Control response header on the page response when the loader completes. Use short max-age for frequently changing data, longer for static-ish content.

Private caching

#[load(cache = "private, max-age=300")]
async fn dashboard(req: &FlowRequest) -> DashData {
    user_dashboard(req).await
}

When not to cache

Omit the cache attribute for personalized or auth-gated loaders. Default behavior sends no Cache-Control override.