Cache Operations (sdk.cache)

High-performance key-value storage at the edge.

Introduction

import { AerostackServer } from '@aerostack/sdk';
 
const sdk = new AerostackServer(env);
await sdk.cache.set('key', 'value');

Features

set(key, value, options)

Store any JSON-serializable data. Currently supports strings, numbers, objects.

Options:

  • ttl: Time-to-live in seconds.
// Cache user profile for 1 hour
await sdk.cache.set('user:123', { name: 'Alice' }, { ttl: 3600 });

get(key)

Retrieve data. Returns null if not found or expired.

const user = await sdk.cache.get('user:123');
if (user) {
  console.log(user.name);
}

delete(key)

Remove a key.

await sdk.cache.delete('user:123');

exists(key)

Check if a key exists without retrieving the value.

if (await sdk.cache.exists('lock:process')) {
  // ...
}

Make sure [[kv_namespaces]] is configured in your aerostack.toml with binding CACHE.