Skip to main content

delete

Function delete 

Source
pub fn delete<'a>(
    ctx: &Ctx,
    key: &'a str,
) -> impl Future<Output = Result<()>> + Send + use<'a>
Expand description

Removes key, e.g. after the data behind it changed (Rails’ Rails.cache.delete).

Deleting an absent key succeeds. Other locations may still read the old value for up to 60 seconds.

Free plan: counts as one KV write (1,000 a day); none with STORE_VAR set to "null".

§Errors

  • Error::Internal (500) when the CACHE binding is missing, naming the fix: ocre g cache adds CACHE: bindings.kv(), to cloudflare.config.ts.
  • Error::Internal when key is empty or longer than 512 bytes.
  • Error::Internal when KV rejects the delete, e.g. past the daily limit (message prefixed with LOG_PREFIX).

§Examples

use axum::extract::{Path, State};
use ocre::{Ctx, Result};

async fn update(State(ctx): State<Ctx>, Path(id): Path<i64>) -> Result<()> {
    // post::update(&ctx, id, changes).await?;
    ocre::cache::delete(&ctx, "posts:recent:v1").await
}