-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature
Currently, unlike Redis, there isn't a default TTL option for Cloudflare KV Binding.
Nevertheless, it's currently possible to set the TTL manually when invoking setItem
. Would be a huge addition to allow for a default TTL to be applied (if not overridden by custom TTL).
This would allow, among other things, auto pruning of stale cache entries when using KV as the default cache.
// I had something like so in mind
// /drivers/cloudflare-kv-binding.ts
setItem(key, value, topts) {
key = r(key);
const binding = getKVBinding(opts.binding);
// Determine which TTL to use
let expirationTtl: number | undefined = undefined;
if (topts?.ttl) {
expirationTtl = Math.max(topts.ttl, opts.minTTL ?? 60);
} else if (opts.ttl) {
expirationTtl = Math.max(opts.ttl, opts.minTTL ?? 60);
} else if (opts.minTTL) {
expirationTtl = opts.minTTL;
}
return binding.put(
key,
value,
{
...topts,
expirationTtl,
}
);
},
Additional information
- Would you be willing to help implement this feature?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request