All spotlights

Product spotlight · September 2024

Keep data between requests with key-value stores

KV stores give your project key-value stores that you manage in the dashboard and that edge functions can read and write, so a function can keep data between requests.

New product KV stores For developers

What it includes

The September 2024 changelog has the full details.

  • Edge function access

    Edge functions can now read and write the key-value stores of your project. Call kvStore.get(), kvStore.set() and kvStore.delete() with the store ID from the KV stores page.

  • Stores in the dashboard

    You can create and delete key-value stores on your project's KV stores page in the dashboard.

  • Items in the dashboard

    On the same page, you can add, edit, view and delete the items in each store.

  • Data between requests

    With a store, a function can keep data from one request to the next, such as short links or settings.

Who it is for

  • Edge developers

    Read and write a store from your edge functions, so that a function can keep its data from one request to the next.

  • Teams that keep settings

    Keep settings in a store, and add, edit or delete them on the KV stores page of your project in the dashboard.

  • Sites with short links

    Keep your short links as items in a store, so that an edge function can read them when a visitor makes a request.

What it is

KV stores are key-value stores for your Quant project. Each store holds items, and you find an item by its key.

An edge function runs on every matching request. With a KV store, the function can also keep data from one request to the next, such as short links or settings. You manage the stores and their items in the dashboard, and your edge functions read and write the same stores.

How it works

You create a store and add its items on the KV stores page of your project. The same page shows the store ID. In your edge function, each kvStore method takes the store ID as its first argument:

  • await kvStore.set(KV_STORE_ID, key, data); stores data under a key.
  • const data = await kvStore.get(KV_STORE_ID, key); reads the data for a key.
  • await kvStore.delete(KV_STORE_ID, key); deletes a key.

For example, a function can read a setting with kvStore.get() on each request. You can then change that setting on the KV stores page.

The Key Value Stores page in the Quant documentation explains how to use a store in an edge function.

Get started

  1. Create a store

    Open your project's KV stores page in the dashboard and create a store.

  2. Add items

    Add, edit and view the items of the store on the same page.

  3. Copy the store ID

    Copy the store ID from the KV stores page to use in your function.

  4. Call it from a function

    Use kvStore.get(), kvStore.set() and kvStore.delete() with that ID.

Related: Explore Edge functions · Documentation · September 2024 changelog

Ready to try it on Quant?

Use KV stores on your own project, or read the docs first.