---
question: Which cache tier do reads and writes use?
kind: overview
---

# Cache

The cache keeps the result of a call under a key, so the next call with the same key skips the work. It is the kernel service `services.cache`: the engine hosts it, and modules reach it through `self.engine.services.cache` for model calls, lookups and rendered pages. It is a stack of tiers: a fast `hot` tier and a durable `cold` tier.

Caching a function is Python only. Super admins can browse, add, edit and delete entries in Nexus, under System › Data › Cache.

<!-- matrix -->

## Backends

`services.cache.adapters` is a list. Each entry is one tier: an `adapter`, a `tier` name (`cold` when you leave it out) and its `config`.

| Adapter | Storage |
|---|---|
| `fs` | Files on local disk |
| `redis` | A Redis server |
| `object_storage` | The engine's object storage service |
| `keyvalue` | The engine's key-value store |
| `nats_rpc` | Another engine's cache, over NATS |

When `config.yaml` has no `cache:` block, as in a new project, the engine uses Redis at `redis://localhost:6379/0` as `hot` and object storage as `cold`. A tier it cannot reach counts as a miss and logs a warning. The keys of each adapter, and how to pick the tiers, are on [Choose a backend](/capabilities/build/platform/choose-a-cache-backend).

## Key concepts

- **Reads go hot, then cold.** `await cache.get(key)` returns the first tier that has the key. A cold hit is not copied into hot.
- **Writes go cold.** `set_text`, `set_json` and `set_binary` write the cold tier only. `cache.hot.set_json(...)` writes hot. `delete` removes the key from every tier.
- **Typed entries.** An entry is text, JSON or binary, and `get` returns it as a `str`, the decoded JSON value or `bytes`. Pickled entries are not supported: `set_pickle` raises `NotImplementedError`.
- **Age, not expiry.** An entry stores when it was written. A `ttl` is checked when you read: an older entry is a miss. Nothing deletes old entries.
- **Shared keys.** Keys are not prefixed with the module. Prefix yours (`my_module:...`).
- **Errors.** `get` raises `CacheNotFoundError` (`naas_abi_sdk.services.errors`) when no tier has a fresh entry. A lost connection or a timeout raises; only a miss or an expired entry moves on to the next tier.
- **Events.** Writes and deletes publish `CacheSet` and `CacheDeleted`, and a failed write `CacheError`, when the engine's event service is up.
- **Dependency.** A module declares `"cache"` in `ModuleDependencies(services=(...))`. The attribute is `self.engine.services.cache`; a module that did not declare it gets a `ValueError`.
