Class for accessing a Fastly Object-store.

An object store is a persistent, globally consistent key-value store.

Note: Can only be used when processing requests, not during build-time initialization.

Example

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.get('hello')

return new Response(await entry.text())
}

addEventListener("fetch", (event) => event.respondWith(app(event)))

Hierarchy

  • ObjectStore

Constructors

Methods

Constructors

  • Creates a new JavaScript ObjectStore object which interacts with the Fastly Object-store named name.

    Parameters

    • name: string

      Name of the Fastly Object-store to interact with. A name cannot be empty, contain Control characters, or be longer than 255 characters.

    Returns ObjectStore

Methods

  • Gets the value associated with the key key in the Object-store. When the key is present, a resolved Promise containing an ObjectStoreEntry will be returned which contains the associated value. When the key is absent, a resolved Promise containing null is returned.

    Parameters

    • key: string

      The key to retrieve from within the Object-store. A key cannot:

      • Be any of the strings "", ".", or ".."
      • Start with the string ".well-known/acme-challenge/""
      • Contain any of the characters "#?*[]\n\r"
      • Be longer than 1024 characters

    Returns Promise<null | ObjectStoreEntry>

  • Write the value of value into the Object-store under the key key.

    Note: Object-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.

    Parameters

    • key: string

      The key to associate with the value. A key cannot:

      • Be any of the strings "", ".", or ".."
      • Start with the string ".well-known/acme-challenge/""
      • Contain any of the characters "#?*[]\n\r"
      • Be longer than 1024 characters
    • value: BodyInit

      The value to store within the Object-store.

    Returns Promise<undefined>

Generated using TypeDoc