Creates a new JavaScript KVStore object which interacts with the Fastly KV store named name.
Name of the Fastly KV store to interact with. A name cannot be empty, contain control characters, or be longer than 255 characters.
Delete the value associated with the key key in the KV store.
The key to delete from within the KV store. A key cannot:
Gets the value associated with the key key in the KV store.
When the key is present, a resolved Promise containing a KVStoreEntry will be returned
which contains the associated value. When the key is absent, a resolved Promise
containing null is returned.
The key to retrieve from within the KV store. A key cannot:
List keys in the KV store, optionally filtered by prefix.
Optionaloptions: { cursor?: string; limit?: number; noSync?: boolean; prefix?: string }Options for filtering and paginating the key list.
Optionalcursor?: stringThe base64 cursor string representing the last listing operation.
Optionallimit?: numberLimit the number of keys provided per listing.
OptionalnoSync?: booleanDo not wait to sync the key list, and instead immediately return the current cached key list. May be faster but possibly out of date.
Optionalprefix?: stringString prefix for keys to list.
A Promise resolving with the list of keys and a cursor for pagination.
Write the value of value into the KV store under the key key.
Note: KV store is 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.
The key to associate with the value in the KV store. A key cannot:
The value to store within the KV store. Maximum size is 30 MB.
Optionaloptions: {Optionalgen?: numberGeneration counter for conditional writes. The write only succeeds if the current generation of the entry matches this value. Must be a positive integer.
Optionalmetadata?: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike>Binary metadata to associate with the entry, up to 1000 bytes.
If passing a string, UTF-8 encoding is used.
Optionalmode?: "overwrite" | "add" | "append" | "prepend"Insert mode, defaults to 'overwrite'.
'overwrite': Replace any existing value for the key.'add': Only insert if the key does not already exist.'append': Append to any existing value for the key.'prepend': Prepend to any existing value for the key.Optionalttl?: numberTTL (time-to-live) for the entry, in seconds.
Class for accessing a Fastly KV store.
A KV store is a persistent, globally consistent key-value store. See Data stores for Fastly services for initialization and usage details.
Note: Can only be used when processing requests, not during build-time initialization.
Example
In this example we connect to a KV store named
'files', save an entry to the store under the key'hello'and then read back the value and return it to the client.