Simple "cache" node, does this exist?

Sometimes when I'm troubleshooting a flow, I want to be able to capture a message at a certain point in the flow and then re-send it on command so I can tweak the downstream code.

What I do now is copy the message from the debug output into an inject node, but I could imagine a node with a button in the middle and pressing it re-generates the most recent message even if the node has been re-deployed since then.

So, the question is, does something like this already exist? I can't seem to find anything

You might be able to lash something up using node-red-contrib-queue-gate. I suggest configuring it for the queueing state, maximum queue size of 1, and Keep Newest Messages. It will still need an inject node attached to send a trigger to release the saved message. This may not be exactly what you want, but it seems close.

1 Like

This can be done with a change node and an inject node. simply save the message in change node to a context variable, then in the inject read the context variable

i.e.

[{"id":"7be26afb.b2b40c","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$ceil($random()*10)","payloadType":"jsonata","x":110,"y":2780,"wires":[["2b1242c2.cb29c6"]]},{"id":"2b1242c2.cb29c6","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload*10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":2780,"wires":[["9ef1060a.c56308","218b7026.69a7b"]]},{"id":"9ef1060a.c56308","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":2780,"wires":[]},{"id":"218b7026.69a7b","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"debug","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2680,"wires":[[]]},{"id":"7aa34328.330444","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"debug","payloadType":"flow","x":510,"y":2720,"wires":[["9ef1060a.c56308"]]}]
3 Likes

Thanks for the responses, I ended up writing a function similar to the inject/change node suggestion:

[{"id":"cd5e5637.8d0508","type":"tab","label":"simple cache","disabled":false,"info":""},{"id":"5b00ca3e.921a94","type":"inject","z":"cd5e5637.8d0508","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"recall","payload":"bar-test","payloadType":"str","x":490,"y":160,"wires":[["8b8023ea.1baaa"]]},{"id":"82620f2c.d95f9","type":"inject","z":"cd5e5637.8d0508","name":"foo-test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"foo-test","payload":"fake string data","payloadType":"str","x":270,"y":180,"wires":[["8b8023ea.1baaa"]]},{"id":"8b8023ea.1baaa","type":"function","z":"cd5e5637.8d0508","name":"cache / recall","func":"if (msg.topic == \"recall\"){\n    var topic = msg.payload\n    var data = flow.get(\"cache.\" + topic);\n    if(!data){\n        node.error(\"no recall data for: \" + topic,msg);\n        return null;\n    }else{\n        return data;\n    }\n}else{\n    flow.set(\"cache.\" + msg.topic,msg);\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":200,"wires":[["3ae504ff.be655c"]]},{"id":"3ae504ff.be655c","type":"debug","z":"cd5e5637.8d0508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":200,"wires":[]},{"id":"6828e502.96caac","type":"inject","z":"cd5e5637.8d0508","name":"bar-test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"bar-test","payload":"{\"foo\":\"fake string data\",\"bar\":[1,1,2,3,5,8,13,21]}","payloadType":"json","x":270,"y":220,"wires":[["8b8023ea.1baaa"]]},{"id":"4d2f0308.f7978c","type":"inject","z":"cd5e5637.8d0508","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"recall","payload":"foo-test","payloadType":"str","x":490,"y":120,"wires":[["8b8023ea.1baaa"]]}]This text will be hidden

Look at message tracer, it will do all that you want and more.
Holding for inspection and breakpoints.

node-red-contrib-msg-tracer

1 Like

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