Saving context variable to the localfilesystem immediately on change

Hi,

I have my node-red flow configured to use localfilesystem as contextStorage. I know that for every 30 seconds context variables are saved to the file system.

Is there a way to save these immediately to the file system as and when they are created,updated or deleted?

Regards,
Kushan

You can configure the flush time as per the docs.. But I have to ask why ?

Yes I understand that the flush time can be configured. But my need is to preserve context data in case of sudden restart of the server.

However rapidly you attempt to update it it can never be instantaneous, there will always be a window after it is changed before it is saved to disk during which the power may fail. That is true even if there were a flag you could set that said that immediately after updating a variable it is to be flushed to disc. The power could still fail in the gap between update and flush.

I am ok to loose data for a second or two and I don't want the flush interval to be too short as well. A flag or some other way for immediate update is what I am looking for.

Again as per the docs you can also set cache to false which should turn it off.

2 Likes

Oh really, I didn't noticed that. That is the solution.
Great thanks.

Just be aware that if you turn off the cache, the store becomes a asynchronous store, which means you cannot do:

var a = flow.get("foo");

You have to use the version with a callback function:

flow.get("foo", function(err, a) {
});
1 Like

Thank you for your valuable advice for saving my time. I was just noticing breaking my flow after cache=false.

Hope it affects to change nodes too.

Now I am a bit confused, if you turn of the cache it gets a synchronous store? You mean asynchronous?
And shouldn't the callback for the get have at least two parameters, because the first one is the error?

Yup - you are quite right, will edit my post. Need more tea.

3 Likes