ObjectStore.prototype.put
The put()
method stores a value
into the Object store under a key
.
Note: Object stores are eventually consistent, this means that the updated contents associated with the key
key
may not be available to read from all edge locations immediately and some edge locations may continue returning the previous contents associated with the key.
Syntax
put(key, value)
Parameters
key
: string- The key to store the supplied value under within the Object store.
value
: ArrayBuffer | TypedArray | DataView| ReadableStream | URLSearchParams | String | string literal- The value to store within the Object store.
Return value
Returns a Promise
which resolves with undefined
when the provided value
has been written into the Object store.
Description
Stores the supplied value
into the Object store under the supplied key
.
The put()
method requires its this
value to be a ObjectStore
object.
If the this
value does not inherit from ObjectStore.prototype
, a TypeError
is thrown.
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
- Is any of the strings
- If the provided
Examples
In this example we connect to an Object Store named 'files'
and save an entry to the store under the key 'hello'
and then read back the value and return it to the client.
/// <reference types="@fastly/js-compute" />
import { ObjectStore } from "fastly:object-store";
async function app(event) {
const files = new ObjectStore('files')
await files.put('hello', 'world')
const entry = await files.put('hello')
return new Response(await entry.text())
}
addEventListener("fetch", (event) => event.respondWith(app(event)))