Skip to main content

clear

Function clear 

Source
pub fn clear<'a>(
    ctx: &Ctx,
    prefix: &'a str,
    limit: usize,
) -> impl Future<Output = Result<Cleared>> + Send + use<'a>
Expand description

Deletes up to limit cached values whose key starts with prefix (Rails’ Rails.cache.clear, bounded): "" for everything, "views/" for fragments, "posts/" for one family of keys. Call it again while Cleared::more is true, e.g. from a scheduled task after a deploy that changed the cached data’s shape.

Free plan: one KV list (of 1,000 a day) plus one KV write per deleted key (1,000 writes a day), so keep limit small; with STORE_VAR set to "null" nothing is deleted.

§Errors

  • Error::Internal (500) when the CACHE binding is missing (ocre g cache adds it).
  • Error::Internal when KV rejects the list or a delete, e.g. past the daily limit.

§Examples

use ocre::{Ctx, Result};

async fn nightly(ctx: Ctx) -> Result<()> {
    let cleared = ocre::cache::clear(&ctx, "views/", 200).await?;
    ctx.log().info(format_args!("cleared {} fragments, more: {}", cleared.deleted, cleared.more));
    Ok(())
}