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
- Your app to Redis 7: GET / SET
- Redis 7 to Data volume: persist
Flows
Storing a session
- The app writes the session under a key with an expiry.
- Redis keeps it in memory and appends it to its file.
- Later requests read it back in well under a millisecond.
Set it up
In the console
- Open Caches and choose New cache.
- Name it and choose its memory.
- Choose Create; its page shows its address.
With the CLI
enclave cache create sessions --waitWith 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.
| Name | Type | Use | What it does |
|---|---|---|---|
name | text | required | Name of the cache: 3–40 lowercase letters, digits or hyphens, starting with a letter. Changing it replaces the cache. |
machine | text | optional | The 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_labels | map of text | optional | Labels the machine must have, when machine isn't set (key=value, all must match). |
max_memory_mib | number | optional | Maximum memory in MiB (64–4096). Changes in place. |
network | text | optional | Network to place it in (default: the default network). Changes in place. |
project | text | optional | The project to create it in. Defaults to the provider's project (ENCLAVE_PROJECT, else default). Changing it replaces the resource. |
subnet | text | optional | Subnet of the network (default: its first). |
host | text | output | Host to connect to from this machine (none in a network without internet). |
id | text | output | Resource ID. |
internal_host | text | output | Host apps use on the EnclaveStack network. |
internal_port | number | output | Port apps use on the EnclaveStack network. |
port | number | output | Port to connect to from this machine (none in a network without internet). |
private_dns | text | output | Name it answers to inside its network: <name>.cache.internal. |
private_ip | text | output | Address 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.