# Persistent context storage

**URL:** <https://discourse.nodered.org/t/persistent-context-storage/37858>\
**Category:** General\
**Created:** [22 December 2020 00:15 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858 "2020-12-22T00:15:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [22 December 2020 00:15 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/1 "2020-12-22T00:15:59Z")

</div>

Hi everyone,  
What a really great feature!  
I put this into my settings.js file, I only need it to update every 10 minutes.  
I wish there was more info on this.  
A couple of questions for you.....

1. Have I done it correctly?
2. Does it only flush if there has been an update or is it as per the flushInterval irrespective?

If it's only if there has been an update, I can reduce the flushInterval back to 30 seconds.

The way I understand it is:

This will use memory:  
var hb\_counter = context.get("c\_hb\_counter") || 0;  
context.set("c\_hb\_counter", hb\_counter);

This will use file:  
var overfly\_array = flow.get("c\_overfly\_array", "disk") || ;  
flow.set("c\_overfly\_array", overfly\_array, "disk");

Am I correct? 🤔

Christmas is coming!! 🎄

Cheers. 🍻  
Paul.

```auto
    contextStorage: {
        default: {
            module:"memory"
        },
        disk: {
            module:"localfilesystem", config:{flushInterval: 600}
        },
    },

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 December 2020 00:54 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/2 "2020-12-22T00:54:52Z")

</div>

> [@FatPilot](#):
>
> Does it only flush if there has been an update or is it as per the flushInterval irrespective?

See this post by Nick...

> [@Working with local storage for Context, Flow and Global Variables](https://discourse.nodered.org/t/working-with-local-storage-for-context-flow-and-global-variables/36320/4):
>
> When you call set on the file system store, if its in synchronous mode, it updates the in-memory cache, then, if there is a pending write already queued up, it just returns. Otherwise, it schedules a write to disk of the cache in 30 seconds time (or whatever you've configured its flush interval to). That means: if this is the first write to context you've done since the last flush to disk, then the write to disk will happen in 30 seconds time. if you'd done a write to context 28 seconds ago …

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [22 December 2020 10:11 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/3 "2020-12-22T10:11:57Z")

</div>

> [@FatPilot](#):
>
> ```auto
> module:"localfilesystem", config:{flushInterval: 600}
> 
> ```

Almost there! you are missing quotes around the flush interval time, and also the comma after the brace.

```auto
    contextStorage: {
        default: {
        module: 'memory'
        },
        disk: {
           module: 'localfilesystem', config: {flushInterval: '600'},
          },
     },

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 December 2020 11:09 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/4 "2020-12-22T11:09:12Z")

</div>

This thread might also be helpful to you [A guide to understanding ‘Persistent Context’](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115)

---

<div class="post-metadata">

**Author:** ![FatPilot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fatpilot/32/38329_2.png) [@FatPilot](https://discourse.nodered.org/u/FatPilot)\
**Post date:** [22 December 2020 13:52 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/5 "2020-12-22T13:52:59Z")

</div>

Hi Paul-Reed,  
Thank you!

Cheers.  
Paul

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 February 2021 13:53 UTC](https://discourse.nodered.org/t/persistent-context-storage/37858/6 "2021-02-20T13:53:07Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
