Skip to main content
Version: 1.0.0

ObjectStore()

The ObjectStore constructor lets you connect your Fastly Compute application to 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.

Syntax

new ObjectStore(name)

Note: ObjectStore() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

  • name : string
    • The Fastly Object store which should be associated with this ObjectStore instance

Return value

A new ObjectStore object.

Exceptions

  • TypeError
    • Thrown if no Object Store exists with the provided name
    • Thrown if the provided name is longer than 255 in length
    • Thrown if the provided name is an empty string
    • Thrown if the provided name does not start with an ascii alphabetical character
    • Thrown if the provided name contains control characters (\u0000-\u001F)

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

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

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