Overview
This node provides a simple caching mechanism within an n8n workflow, allowing users to store, retrieve, update, and delete cached data by key. It is useful for scenarios where intermediate results or frequently accessed data need to be temporarily stored to improve workflow efficiency or reduce repeated external calls.
Common use cases include:
- Caching API responses to avoid redundant requests.
- Storing temporary state or flags between workflow executions.
- Managing small datasets that multiple nodes in the workflow can access.
- Implementing custom rate limiting or throttling logic by caching counters.
For example, you could cache user session data after authentication and reuse it in subsequent workflow steps without re-authenticating.
Properties
Name | Meaning |
---|---|
操作 (action) | The cache operation to perform. Options: 获取 (GET), 创建 (SET), 哈希 (ADD), 删除 (DEL). |
缓存Key (key) | The unique key identifying the cache entry. |
缓存字段 (field) | Cache field name used only with the "哈希" (ADD) operation. If empty, all input parameters are cached. |
缓存Value (value) | The value to store in the cache. Required for "创建" (SET) and "哈希" (ADD) operations. |
缓存过期时间 (ttl) | Time-to-live in seconds for the cache entry. Required for "创建" (SET) and "哈希" (ADD) operations. |
同步加载到工作流Execution (syncExecution) | Whether to load the cached data synchronously into the workflow execution's custom data storage. |
Output
The node outputs JSON data representing the result of the cache operation:
- For GET: Outputs the cached data associated with the given key. This can be any JSON object previously stored.
- For SET, ADD, and DEL: Outputs a JSON object with
{ code: 0, action: <operation> }
indicating success. - If
syncExecution
is enabled and the cached data is an object, it will also be loaded into the workflow execution's custom data for synchronous access by other nodes.
The node does not output binary data.
Dependencies
- The node uses an internal utility module (
./util
) which manages an in-memory cache (dataCache
) and helper functions to parse objects and retrieve cached data. - No external services or API keys are required.
- No special environment variables or n8n credentials are needed.
Troubleshooting
- Empty or missing cache key: The node requires a non-empty cache key; ensure the "缓存Key" property is set.
- Invalid TTL values: TTL must be a non-negative number; negative or invalid inputs default to zero.
- Data parsing errors: When using the "哈希" (ADD) operation, the "缓存Value" should be a valid JSON string if complex data is intended; otherwise, parsing may fail.
- Cache miss on GET: If no data exists for the given key, the output will be empty or undefined.
- Sync execution issues: Enabling synchronous loading (
syncExecution
) expects cached data to be an object; non-object data will not be loaded into execution custom data.
If the node throws errors during execution, check the input parameters for correctness and ensure the cache key and values are properly formatted.