|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +toc: api-toc.html |
| 4 | +title: Local Filesystem Context Store |
| 5 | +--- |
| 6 | + |
| 7 | +**New in 0.19** |
| 8 | + |
| 9 | +The Local Filesystem Context store holds context data in local files. By default it |
| 10 | +caches context data in memory, allowing both synchronous and asynchronous access. |
| 11 | + |
| 12 | +If the caching mode is disabled, the store only supports asynchronous access. |
| 13 | + |
| 14 | +### Configuration |
| 15 | + |
| 16 | +To create a file store, the following configuration can be used. |
| 17 | + |
| 18 | +{% highlight javascript %} |
| 19 | +contextStorage: { |
| 20 | + default: { |
| 21 | + module:"file", |
| 22 | + config: { |
| 23 | + // see below |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | +{% endhighlight %} |
| 28 | + |
| 29 | +### Options |
| 30 | + |
| 31 | +The file store can take the following configuration options: |
| 32 | + |
| 33 | +Options | Description |
| 34 | +----------------|------------------------------ |
| 35 | +`dir` | The directory to store the `base` directory in. Default: the user directory, `~/.node-red` |
| 36 | +`base` | The base directory under which context data is stored. Default: `"context"` |
| 37 | +`cache` | Whether to cache context in memory. Default: `true` |
| 38 | +`flushInterval` | If caching is enabled, the minimum interval between writes to storage, in seconds. Default: `30` |
| 39 | + |
| 40 | +The default configuration for a `file` context store is to use the directory `~/.node-red/context`, with caching |
| 41 | +enabled and writes to storage happening every 30 seconds. |
| 42 | + |
| 43 | +The `flushInterval` is provided to minimise wear on the underlying storage, such |
| 44 | +as on a Raspberry Pi's SD card. Note that if Node-RED is unexpectedly killed, any data |
| 45 | +that has not yet been flushed will be lost. |
| 46 | + |
| 47 | +### Implementation details |
| 48 | + |
| 49 | +This context store uses a separate file for each context scope. At the top level |
| 50 | +is a directory for each flow scope and one for the global scope. Within each |
| 51 | +flow scope directory is a file containing the flow scope, `flow.json` and a file |
| 52 | +for each node context. |
| 53 | + |
| 54 | +``` |
| 55 | + $HOME/.node-red/context |
| 56 | + ├── global |
| 57 | + │ └── global.json |
| 58 | + ├── <id of Flow 1> |
| 59 | + │ ├── flow.json |
| 60 | + │ ├── <id of Node a>.json |
| 61 | + │ └── <id of Node b>.json |
| 62 | + └── <id of Flow 2> |
| 63 | + ├── flow.json |
| 64 | + ├── <id of Node x>.json |
| 65 | + └── <id of Node y>.json |
| 66 | +``` |
0 commit comments