The Cache node, available in the Storage category, allows you to temporarily store data in cache memory so you can retrieve it later from any point in the integration.
Unlike data associated with a flow, values stored in cache remain available even after reaching the Step Close node. You can also configure whether the data will be exclusive to one session or available to all sessions of the instance.
Node configuration
Below you will find a description of the fields available to configure the node:
1. Name:
Allows you to customize the node name, which will be visible in the Studio workspace.
2. Key (required):
Defines the name of the key under which the data will be stored in cache and that you will later use to retrieve it.
This field supports the Mustache syntax {{varExample}} to access properties of the msg object, for example, msg.varExample.
3. Global:
Defines the scope of the stored data:
- False: the value will be available only in the user session where it was stored.
- True: the value will be available to all sessions of the instance.
4. Method:
Allows you to select one of the four available methods to operate on data stored in cache: GET, SET, INCREMENT, and DELETE.
GET
Allows you to retrieve data previously stored in cache. Data availability will depend on the Global value configured when it was stored:
- True: it will be available to all sessions, as a shared bot cache.
- False: it will be available only in the session where it was saved.
If the value does not exist, the result will be null.
This method includes the following fields:
- Output: defines the name of the variable where the retrieved value will be stored. You can use an existing variable or create a new one.
- Decrypt: allows you to decrypt data previously stored using the Encrypt option.
SET
Allows you to store information in cache using a key so you can retrieve it later.
It includes the following fields:
- Input: indicates the name of the msg variable, string, or JSON you want to store.
- Expires: defines how long the data will remain in cache, expressed in minutes. The default value is 60 minutes. You can set a minimum of 1 minute and a maximum of 1440 minutes (24 hours).
- Encrypt: allows you to encrypt data before storing it. If you enable this option, you must enable Decrypt when retrieving it in order to read its content.
INCREMENT
Works as a counter and, each time it runs, increases the stored value by 1. If the variable does not exist, it is automatically initialized to 1.
In this method, you must complete the Output field, just like in GET, to define where the result will be stored.
DELETE
Allows you to delete a key and its associated value previously stored in cache. To do so, you must enter the corresponding key in the Key field.
When data stored in cache expires or is deleted, its value becomes null.
The Global value must match the one used when the data was saved. For example, if it was stored with Global = True, the DELETE node must also be configured with Global = True. The same applies when using False.
Key points
To ensure the node works correctly, keep the following considerations in mind:
1. msg._studio property
You must not delete or modify this property, as it is required for the node to work.
The agentbot user id must be stored in the msg._studio.sessionId property. Existing configurations that use other session identifiers will continue to work normally.
2. Empty or undefined variables
If you try to store data from a variable of the msg object whose value is empty, null, or undefined, a warning will be displayed in the Debug console in the following format:
"Warning: {{msg property name}} maybe empty or undefined."
3. Missing agentbot user id
If you use any of the available methods (GET, DELETE, INCREMENT, or SET) with Global = False and the agentbot user id is not present when the node receives the request, the following warning message will be displayed in the Studio Debug window:
"The agentbot user ID is not present in the msg object, and global is false. Stored data may be unreachable."
In this scenario, the data will be stored globally and you must also retrieve it using Global = True.
4. Using the Cache node with HTTP_IN
If you use the Cache node together with an HTTP_IN node, you must set the session ID manually. You can do so in any of the following properties, respecting this order of precedence:
- msg._studio.sessionId
- msg.payload.agentbot_user.id
- msg.payload.id
You can download the example flow at this link.
In the following video, we show you how to configure the node: