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_keyis 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_ttlis 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_intonames the variable that receives the value, written likesave_body:.
What each effect does
cache_setstores 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_getputs the stored value inctx.<cache_into>and leaves the message as it was. On a miss, including an entry whose time has passed, the variable isnull.cache_delremoves 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-lookuptenant: acmeeffects: [cache_get, cache_set, http_egress]---
## Step: recalleffects: [cache_get]cache_key: "{{ $.product }}"cache_into: hitsave_body: asked
## Step: guard```routewhen ctx.hit != null: call answerotherwise: call fetch```
## Step: answer```ntd{ "price": {{ ctx.hit.price }} }```
## Step: fetcheffects: [http_egress]endpoint: https://prices.example.com/lookupmethod: POST
## Step: remembereffects: [cache_set]cache_key: "{{ ctx.asked.product }}"cache_ttl: 3600Scope 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.