Skip to content

Commit

Permalink
Merge pull request #4984 from FlowFuse/sumitshinde-84-patch-1
Browse files Browse the repository at this point in the history
Update persistent-context.md
  • Loading branch information
ZJvandeWeg authored Jan 6, 2025
2 parents b7d0463 + f4c2b98 commit 1af9145
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions docs/user/persistent-context.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
---
navTitle: FlowFuse Persistent Context
---

# FlowFuse Persistent Context

Some Node-RED flows need a way to persist context values between restarts and FlowFuse stack
updates but context data is ephemeral by default. With FlowFuse Team and Enterprise tiers,
persistent context storage is possible and it survives restarts, upgrades and more.
Some Node-RED flows require the ability to persist context values between restarts and FlowFuse stack updates. By default, context data in Node-RED is ephemeral, meaning it does not survive restarts or stack updates. With FlowFuse Starter, Team and Enterprise tiers, however, you can enable **persistent context storage**, ensuring that your context values persist across restarts, upgrades, and more.

## Usage

In your Node-RED, you will now have the option to store values in 2 context stores:
* **Memory**: This is for ephemeral context where you do not want it to be persisted.
* **Persistent**: This is for persistent context where you want values to persist restarts and upgrades.
In Node-RED with FlowFuse, you now have two context store options:

1. **Memory Context**: This is the default ephemeral context. Values stored in memory are not persistent and will be lost when Node-RED restarts or the Node-RED stack is updated.

2. **Persistent Context**: This allows context values to persist even when Node-RED restarts, updates.

The amount of persistent storage available to you depends on the FlowFuse plan you're subscribed to. FlowFuse offers different storage sizes for each plan, allowing you to select the appropriate level of storage for your needs. For detailed information on storage options, please refer to the [pricing page](https://flowfuse.com/pricing/).

### How to Use FlowFuse Persistent Context

Using persistent context in Node-RED is similar to using memory context, with the key difference being that you specify the storage type for your context data. Here’s how to use persistent context it:

#### Using Persistent Context in Nodes

When configuring persistent context in different nodes (e.g., Change, Inject, or Switch nodes), you can select the type of context storage to use. By default, the context type is set to **Memory**, but you can change it to **Persistent** to store values across restarts.

- **Change Node, Inject Node, Switch Node**:
When you configure these nodes to store or access context data, you’ll notice a storage option at the right corner. By default, it will be set to **Memory**. To make the context **persistent**, simply switch the selection to **Persistent**.

![Persistent Store Option in Change Node](https://flowfuse.com/img/variables-in-node-red-change-node-persistent-store-option--UYd_d_m4p-528.webp)

#### Using Persistent Context in Function Nodes

In **Function nodes**, you interact with context data using the `set` and `get` methods. These methods allow you to specify where the context data should be stored or accessed from.

- **Setting Context**:
To set a persistent context value, use the `set` method with three arguments. The third argument specifies the context store, which should be set to **persistent**. For example:

```javascript
context.set('myKey', 'myValue', 'persistent');
```

This argument is optional and defaults to memory. This means that if you leave it empty, it will use memory as the context store.

- **Getting Context**:

When retrieving persistent context, use the `get` method with two arguments. The second argument is optional and specifies the context store (either memory or persistent).

Example:

```javascript
var value = context.get('myKey', 'persistent');
```

FlowFuse provides 1MB of context storage per Node-RED instance.
If you don't specify the store, it defaults to memory.

For more information on Context, head over to the [Node-RED Working with context](https://nodered.org/docs/user-guide/context) guide.
For more detailed information, refer to the article [Understanding Node, Flow, Global, and Environment Variables in Node-RED](https://flowfuse.com/blog/2024/05/understanding-node-flow-global-environment-variables-in-node-red/).

0 comments on commit 1af9145

Please sign in to comment.