Skip to content

Cache

Three effects give a flow a small cache, so a message does not ask a partner for what an earlier message already fetched. cache_set keeps a value under a key for a number of seconds, cache_get reads it back, and cache_del removes it.

A cache is not an authority. A read that finds nothing is always a legal answer, so a flow written for a cache asks the partner again on a miss. To stop the same message from running twice, use dedup_key: instead.

Step keys

Effect Required keys Refused keys
cache_get cache_key, cache_into cache_ttl
cache_set cache_key, cache_ttl cache_into
cache_del cache_key cache_ttl, cache_into

A step carries one cache effect. Every missing or refused key is an error at publication, which names the key.

  • cache_key is text with {{ ... }} parts, evaluated for each message. It may be a constant, so a flow can keep one value for all its messages. Once evaluated it must hold something besides spaces and be at most 512 bytes.
  • cache_ttl is the number of seconds an entry lives, from 1 to 2 592 000 (30 days). It is a whole number or a {{ ... }} template that evaluates to one. A number outside the range written in the file is refused at publication; one that evaluates outside it fails the step.
  • cache_into names the variable that receives the value, written like save_body:.

What each effect does

  • cache_set stores the step’s input as JSON. Setting a key again replaces the value and restarts the lifetime. A step whose input is empty (null) or XML fails: an empty value is how a miss is told, and XML has no JSON form.
  • cache_get puts the stored value in ctx.<cache_into> and leaves the message as it was. On a miss, including an entry whose time has passed, the variable is null.
  • cache_del removes the entry. Removing one that is not there succeeds.

If the store cannot be read or written, the step fails. cache_get never reports a store failure as a miss.

Example

The flow asks the partner only when the cache has no price for the product.

---
flowmarkdown_version: "0.1"
flow: price-lookup
tenant: acme
effects: [cache_get, cache_set, http_egress]
---
## Step: recall
effects: [cache_get]
cache_key: "{{ $.product }}"
cache_into: hit
save_body: asked
## Step: guard
```route
when ctx.hit != null:
call answer
otherwise:
call fetch
```
## Step: answer
```ntd
{ "price": {{ ctx.hit.price }} }
```
## Step: fetch
effects: [http_egress]
endpoint: https://prices.example.com/lookup
method: POST
## Step: remember
effects: [cache_set]
cache_key: "{{ ctx.asked.product }}"
cache_ttl: 3600

Scope and limits

An entry belongs to the tenant and the flow that run the step. Another tenant, or another flow of the same tenant, using the same key gets a miss, and there is no key that names them.

Entries are kept in the installation’s state, so every engine that shares the state directory sees the same entries, and they survive a restart. An entry past its lifetime is never returned.

Limit Value
Key, once evaluated 512 bytes
Value, as JSON 65 536 bytes
Lifetime 1 to 2 592 000 seconds
Live entries per flow 10 000

A cache_set that would be the 10 001st live entry fails the step with cache full; the platform never drops a live entry to make room. Replacing an existing key at the limit is accepted, and expired entries do not count. The same four numbers are in Limits and constraints.

What reaches the logs and the disk

The key is stored as a fingerprint, not as text. The value is message content and is stored as it is, protected the way the installation’s other state is: by the permissions of the state directory. Neither the key nor the value is written to the log, a trace or an error message.

Engines that start without a state key

The fingerprint needs the installation’s state key. An engine started without one fails any step with a cache effect, and the message names the setting to provide.