Store entries in context with a time to live (TTL)
This flow replicates the TTL (Time to live) feature of certain key-value stores like Redis.
It uses a trigger object to delete entries after a specified delay and will extend the delay if an incoming key is already present.
[{"id":"551a93777b4c2e23","type":"group","z":"87024fb85183e3f9","name":"Initialize empty object at startup","style":{"label":true},"nodes":["c0bb3fd3436dfc4c","7ab3f8ecc66ea58c"],"x":314,"y":139,"w":392,"h":82},{"id":"c0bb3fd3436dfc4c","type":"inject","z":"87024fb85183e3f9","g":"551a93777b4c2e23","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":430,"y":180,"wires":[["7ab3f8ecc66ea58c"]]},{"id":"7ab3f8ecc66ea58c","type":"change","z":"87024fb85183e3f9","g":"551a93777b4c2e23","name":"","rules":[{"t":"set","p":"data","pt":"flow","to":"{}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":180,"wires":[[]]},{"id":"215773ec4117ae54","type":"group","z":"87024fb85183e3f9","name":"Create entries with a time to live, keys with the same name will extend the time to live","style":{"label":true},"nodes":["0050bf2ab4d967d3","5b11029bda24ca5a","55120c5916dd3c28","02fce9ad76f979e8","5efa84993f119c4b","e2aec835fb79f1ed"],"x":314,"y":279,"w":772,"h":122},{"id":"0050bf2ab4d967d3","type":"inject","z":"87024fb85183e3f9","g":"215773ec4117ae54","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":360,"wires":[["e2aec835fb79f1ed"]]},{"id":"5b11029bda24ca5a","type":"change","z":"87024fb85183e3f9","g":"215773ec4117ae54","name":"","rules":[{"t":"set","p":"data[msg.payload]","pt":"flow","to":"{\"foo\": 3}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":320,"wires":[[]]},{"id":"55120c5916dd3c28","type":"change","z":"87024fb85183e3f9","g":"215773ec4117ae54","name":"","rules":[{"t":"delete","p":"data[msg.payload]","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":360,"wires":[[]]},{"id":"02fce9ad76f979e8","type":"inject","z":"87024fb85183e3f9","g":"215773ec4117ae54","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"mario","payloadType":"str","x":410,"y":320,"wires":[["e2aec835fb79f1ed"]]},{"id":"5efa84993f119c4b","type":"trigger","z":"87024fb85183e3f9","g":"215773ec4117ae54","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"topic","topic":"payload","outputs":1,"x":700,"y":360,"wires":[["55120c5916dd3c28"]]},{"id":"e2aec835fb79f1ed","type":"junction","z":"87024fb85183e3f9","g":"215773ec4117ae54","x":560,"y":340,"wires":[["5efa84993f119c4b","5b11029bda24ca5a"]]}]