Skip to main content

cached_render

Function cached_render 

Source
pub async fn cached_render<F, Fut>(
    cache: &dyn Cache,
    key: &str,
    ttl: Option<Duration>,
    compute: F,
) -> String
where F: FnOnce() -> Fut, Fut: Future<Output = String>,
Expand description

Return the cached fragment for key, or compute and store it.

compute runs only on a miss or a cache error. Pass the result to your template as a variable, such as {{ sidebar_html | safe }}.

ttl follows Cache::set: None stores with no expiry.

A cache error is logged and treated as a miss, so the caller always gets a value.