Cache a value with a TTL or expiration

kv

// what it does

Stores a value that KV auto-expires. `--ttl` sets seconds-from-now; `--expiration` sets an absolute Unix timestamp. Use `--path` to load the value from a file instead of passing it inline (the two are mutually exclusive). This is the classic pattern for edge-cached HTML or JSON.

// shell

$ wrangler kv key put "cache:home" "$(cat page.html)" --binding=CACHE --ttl 3600
$ wrangler kv key put KEY --binding=CACHE --path ./value.json --expiration 1750000000

// gotcha

Minimum TTL is 60 seconds — smaller values are rejected. KV is eventually consistent, so a fresh write can take up to ~60s to appear at every edge location.