Are Flows Stored In A Cache?

Hello,
I've been using a MongoDB collection instead of local flow.json file to store flows in Node Red. My problem is that when I change the flows in the database manually, changes doesn't reflect to editor. Despite the fact It makes another GET request for flows.

This is the same when using the local flows.json. If I delete a debug node from my local flow.json file, I still see it in the editor when I hit refresh. But if I make the changes before instantiating a Node Red instance, changes are reflected in the editor.

My questions is that once the Node Red runtime is started does it make a request and store the response in some kind of cache and use it until the flow is deployed? If so, how can I disable the said cache or make node-red read from database again, just like when first initiated, everytime I hit refresh on my browser?

flows are not cached (or rather not like you think)

They are loaded into the Node-RED runtime (server side) at startup.

When the client (browser) requests the flows via the API, they are returned from the running server (i.e. from the runtime that was created on startup ~ from the flows JSON).

So you can call it cached but in reality, you are actually getting a JSON representation of the running flows - NOT the flows stored on disk (or in database). That distinction is important.

1 Like

Is there any way to overwrite the representation from the running server without restarting it again? Couldn't the client call the same API it used during instantiation? I couldn't manage to find an API in the DOCS which gets called in the case of refreshing.

Yes*. This is what happens when you do a full deploy. The API is documented here: POST /flows : Node-RED

* Yes to not restarting the whole node-red service but the deploying of flows WILL cause the runtime to destroy all running nodes and re-instantiate them - thats what happens when you deploy.

1 Like

Using the API endpoint that @Steve-Mcl has pointed you at - but use the reload value for the Node-RED-Deployment-Type header. This will tell the runtime to reload the flow configuration from storage.

3 Likes

Apologies, Nick is correct, use the reload header to reload flows from manually edited DB entry.

NOTE: To be clear - this will still restart the runtime (i.e. nodes will be destroyed and re-instantiated from the flows JSON in the database)

1 Like

I should edit the post function in flows.js which is inside the editor-api/lib/admin directory right?

Shouldn't I use GET/ flows? When I refresh the browser I can only see GET requests made. POSTs only happen when I hit deploy. I want flows.json to be re-read when I refresh the page. Alternatively I might use HTTP request node to change the active flow. Which API should i use in that case?

For what reason? There should be no reason to edit source code of the core application to perform actions.

If you modified the source code to make that happen, you would effectively be restarting the runtime every time.

1 Like

I thought I had to override methods in source code since I wanted NODE-RED to behave that way all the time. But open further thinking, I am just making post requests from an outer source, since I might need the original functionality of the program in the future. That solved my problem, thank you.

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