Skip to content

Key Value Stores

Key Value (KV) Stores provide a simple and efficient way to store and retrieve data at the edge. They can be used to store configuration data, user preferences, or any other data that needs to be quickly accessed by your edge functions.

Getting Started

To begin using KV Stores:

  1. Navigate to the “Compute > K/V Stores” section in the QuantCDN dashboard
  2. Click “Create New Store” to create a new KV store
  3. Give your store a name and description
  4. Once created, you’ll receive a unique identifier for your store

Managing Data

The QuantCDN dashboard provides a simple interface to:

  • Add new key-value pairs
  • Edit existing values
  • View all stored data
  • Search for specific keys
  • Delete key-value pairs

Using KV Stores in Edge Functions

KV Stores can be easily integrated into your edge functions using the kvStore object.

Storing Data

To store data in a KV store:

await kvStore.set(KV_STORE_ID, key, data);

Retrieving Data

To retrieve data from a KV store:

const data = await kvStore.get(KV_STORE_ID, key);

Deleting Data

To delete data from a KV store:

await kvStore.delete(KV_STORE_ID, key);

JSON Data Handling

When storing JSON data in a KV store, the data is automatically encoded when stored and decoded when retrieved. This means you can directly store and retrieve JavaScript objects without manual JSON parsing.

// Storing an object
const user = { name: 'John', age: 30 };
await kvStore.set(USERS_KV_STORE, 'user123', user);
// Retrieving the object
const userData = await kvStore.get(USERS_KV_STORE, 'user123');
// userData is automatically parsed as { name: 'John', age: 30 }

Example Use Cases

KV Stores can be used for various purposes, such as:

  • Storing user preferences or settings
  • Caching API responses
  • Managing feature flags
  • Storing configuration data
  • Maintaining rate limiting counters
  • Storing temporary session data