Skip to content

Commit 5454ebb

Browse files
committed
More context store docs
1 parent b06e9db commit 5454ebb

5 files changed

Lines changed: 102 additions & 4 deletions

File tree

_includes/api-toc.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<ul>
3333
<li class="toctitle{% if page.url == "/docs/api/context/" %} active{% endif %}"><a href="/docs/api/context/">Context Store API</a>
3434
<li {% if page.url contains "/docs/api/context/methods" %}class="active"{% endif %}><a href="/docs/api/context/methods">Methods</a>
35+
<li {% if page.url contains "/docs/api/context/store/memory" %}class="active"{% endif %}><a href="/docs/api/context/store/memory">Memory store</a>
36+
<li {% if page.url contains "/docs/api/context/store/localfilesystem" %}class="active"{% endif %}><a href="/docs/api/context/store/localfilesystem">File store</a>
3537
</ul>
3638
</li>
3739
<li class="tocheader">

docs/api/context/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ title: Context Store API
99
The Context Store API provides a pluggable way to configure where context data is
1010
stored.
1111

12-
By default, Node-RED uses a memory-based implementation of this API. It also provides
13-
a file-based implementation.
12+
By default, Node-RED uses a [memory-based implementation](store/memory) of this API. It also provides
13+
a [file-based implementation](store/localfilesystem).
1414

15-
The API functions are documented [here](methods/).
15+
To create a custom Context Store, a module should create that implements the [Store Module API](#store-module-api).
1616

1717
### Configuration
1818

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
```

docs/api/context/store/memory.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: docs
3+
toc: api-toc.html
4+
title: Memory Context Store
5+
---
6+
7+
**New in 0.19**
8+
9+
The Memory Context store is the default store used by Node-RED. It holds all
10+
context data in memory and is wiped whenever Node-RED restarts. It provides both
11+
synchronous and asynchronous access.
12+
13+
### Configuration
14+
15+
To create a memory store, the following configuration can be used.
16+
17+
{% highlight javascript %}
18+
contextStorage: {
19+
default: {
20+
module:"memory",
21+
}
22+
}
23+
{% endhighlight %}
24+
25+
### Options
26+
27+
The memory store does not provide any configuration options.

docs/user-guide/context.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ contextStorage: {
6363
{% endhighlight %}
6464

6565
Node-RED provides two built-in store modules: `memory` and `file`. It is also
66-
possible to create custom store plugins - full details are on the [api pages](../api/context/).
66+
possible to create custom store plugins.
67+
68+
Full details on the built-in modules, and how to create custom modules, is
69+
available on the [api pages](../api/context/).
6770

6871
Stores can provide either synchronous or asynchronous access. Synchronous access
6972
means a call to get data from the store returns immediately with the value. Asynchronous

0 commit comments

Comments
 (0)