Caches

Redis in memory, written to disk, for sessions and fast lookups.

Overview

A cache is a Redis server: very fast storage in memory for what your app reads often or keeps for a short time. It also writes to disk, so it comes back with its data after a restart.

When to use it

  • Sessions of logged-in users.
  • Rate limits on an API.
  • The result of a slow query for a few minutes.

How it works

Redis 7
redis:7-alpine with append-only persistence on a volume.
Eviction
A memory limit you choose (64 – 4096 MiB); when full, the keys used least recently go first.

One Redis container per cache, its data on a volume, reachable as <name>.cache.internal:6379 in its network. Backups ask Redis for a fresh snapshot and stream it to a bucket.

Architecture

Caches architectureApps keep short-lived data in Redis; it writes to its own volume.GET / SETpersistYour appRedis 7sessions.cache.internal:6379Data volumeappend-only file
Apps keep short-lived data in Redis; it writes to its own volume.
  • Your app to Redis 7: GET / SET
  • Redis 7 to Data volume: persist

Flows

Storing a session

  1. The app writes the session under a key with an expiry.
  2. Redis keeps it in memory and appends it to its file.
  3. Later requests read it back in well under a millisecond.

Set it up

In the console

  1. Open Caches and choose New cache.
  2. Name it and choose its memory.
  3. Choose Create; its page shows its address.

With the CLI

enclave cache create sessions --wait

With OpenTofu

OpenTofu configuration
resource "enclave_cache" "sessions" {
  name           = "sessions"
  max_memory_mib = 256
}

Settings reference

Every setting and output of the OpenTofu resource; the console and the CLI use the same names in their own words. Generated from platform 4d30582.

enclave_cache
NameTypeUseWhat it does
nametextrequiredName of the cache: 3–40 lowercase letters, digits or hyphens, starting with a letter. Changing it replaces the cache.
machinetextoptionalThe machine to run on (default: EnclaveStack chooses, and this reads back its choice). Changing it moves the resource, with its data, in place; apply waits for the move.
machine_labelsmap of textoptionalLabels the machine must have, when machine isn't set (key=value, all must match).
max_memory_mibnumberoptionalMaximum memory in MiB (64–4096). Changes in place.
networktextoptionalNetwork to place it in (default: the default network). Changes in place.
projecttextoptionalThe project to create it in. Defaults to the provider's project (ENCLAVE_PROJECT, else default). Changing it replaces the resource.
subnettextoptionalSubnet of the network (default: its first).
hosttextoutputHost to connect to from this machine (none in a network without internet).
idtextoutputResource ID.
internal_hosttextoutputHost apps use on the EnclaveStack network.
internal_portnumberoutputPort apps use on the EnclaveStack network.
portnumberoutputPort to connect to from this machine (none in a network without internet).
private_dnstextoutputName it answers to inside its network: <name>.cache.internal.
private_iptextoutputAddress in its network.

Limits and security

Good to know

  • 64 – 4096 MiB of memory.
  • Purge empties it at once.

Security

  • Reachable only inside its network; add a firewall to narrow who may connect.