Skip to content

Boilerplate: Valkey persistence for external data ​

Examples for caching volatile upstream API payloads. Not tied to OAuth or sessions.

Option A β€” Single Valkey with rdb+aof ​

Typical customer setup: one Valkey, persistence on, plugin uses fastify.cache.

js
import { defineRacletteConfig } from "@raclettejs/core"

export default defineRacletteConfig({
  name: "my-app",
  services: {
    cache: {
      enabled: true,
      port: 6379,
      volume: "raclette-cache-data",
    },
  },
  backend: {
    cache: {
      persistence: "rdb+aof",
      RDB_OPTIONS: "3600 1 300 100 60 10000",
    },
  },
})

Plugin: fastify.cache.get / forceUpdate with ttl: -1 and an interval task to refresh.

Option B β€” Ephemeral + persistent (kind: valkey) ​

Primary cache stays ephemeral; a second Valkey is declared in config. Dev Compose and backend env vars are generated automatically.

js
import { defineRacletteConfig } from "@raclettejs/core"

export default defineRacletteConfig({
  services: {
    cache: {
      enabled: true,
      port: 6379,
      volume: "raclette-cache",
    },
    cachePersistent: {
      kind: "valkey",
      enabled: true,
      port: 6380,
      name: "my-app-cache-persistent",
      volume: "my-app-cache-persistent",
      persistence: "rdb+aof",
      RDB_OPTIONS: "3600 1 300 100 60 10000",
    },
  },
  backend: {
    cache: { persistence: "none" },
  },
})

yarn raclette dev injects:

bash
CACHE_URL=redis://cache:6379
RACLETTE_VALKEY_CACHE_PERSISTENT_URL=redis://my-app-cache-persistent:6379

Plugin: createCacheService(fastify.fastify.valkeys.cachePersistent, { prefix: pluginKey, defaultTtl: -1 }) β€” see Persistent external data.

For production, point RACLETTE_VALKEY_CACHE_PERSISTENT_URL at your managed cluster, or set enabled: false on the config entry and configure the env var only in deployment.