cache_get
Retrieve a value from the cache (memory or file-based).
Parameters
- keystringrequired
- Cache key to look up. Supports
${ctx.key}interpolation. - output_keystringdefault "cached_value"
- Context key where the retrieved value is stored.
- backendstringdefault "memory"
- Storage backend:
"memory"(process-global bounded cache) or"file"(JSON files on disk). - cache_dirstringdefault IRONFLOW_CACHE_DIR / ".ironflow_cache"
- Directory for file-based cache entries. Only used when
backendis"file". Per-node value overrides the env var.
Expired entries are automatically removed on access (from both memory and file backends).
cache_get and cache_set apply the same interpolation rules to key, so a value stored with key = "llm:${ctx.prompt_hash}" can be read back with the same expression. The interpolated key is also returned by cache_set as cache_key.
Context Output
<output_key>(defaultcached_value) — the cached value, ornullif not found / expired.cache_hit—trueif a valid (non-expired) entry was found,falseotherwise.
Example
Memory backend
local flow = Flow.new("read_from_memory_cache")
flow:step("lookup", nodes.cache_get({
key = "user_token:${ctx.user_id}",
output_key = "token",
backend = "memory"
}))
flow:step("done", nodes.log({
message = "Hit: ${ctx.cache_hit}, Value: ${ctx.token}"
})):depends_on("lookup")
return flow
Environment
IRONFLOW_CACHE_MAX_ENTRIEScontrols the process-global memory backend size. Default:10000.IRONFLOW_CACHE_DIRcontrols the default file backend directory whencache_diris not set. Default:.ironflow_cache.
File backend
local flow = Flow.new("read_from_file_cache")
flow:step("lookup", nodes.cache_get({
key = "${ctx.user_id}_token",
output_key = "token",
backend = "file",
cache_dir = "/tmp/my_cache"
}))
flow:step("done", nodes.log({
message = "Hit: ${ctx.cache_hit}, Value: ${ctx.token}"
})):depends_on("lookup")
return flow