KVStore.prototype.delete
Deletes the value associated with the key key
in the KV store.
Syntax
delete(key)
Parameters
key
: string- The key to retrieve from within the KV-store.
Return value
Returns undefined
Exceptions
TypeError
- If the provided
key
:- Is any of the strings
""
,"."
, or".."
- Starts with the string
".well-known/acme-challenge/"
- Contains any of the characters
"#?*[]\n\r"
- Is longer than 1024 characters
- Does not exist
- Is any of the strings
- If the provided
Examples
In this example we connect to an KV Store named 'files'
and save an entry to the store under the key 'hello'
and then delete the entry.
/// <reference types="@fastly/js-compute" />
import { KVStore } from "fastly:kv-store";
async function app(event) {
const files = new KVStore('files')
await files.put('hello', 'world')
await files.delete('hello')
const entry = await files.get('hello')
if (entry) {
return new Response(await entry.text())
} else {
return new Response('no file named hello exists')
}
}
addEventListener("fetch", (event) => event.respondWith(app(event)))