Keep variables between executions

Hello, I’m trying to create a workflow that extracts the coordinates of a random city starting from a file containing thousands of cities information to create a wallpaper of the city map.

The workflow works pretty well, the only drawback is that each time it’s run it takes some seconds to read the binary file (around 5MB) and some more seconds to move Binary data to JSON.

I haven’t found it in the documentation, but I’m wondering if it’s possible to “save” the JSON object in memory, so that it will be immediately available on the next workflow execution without having to read it from the file system everytime.

Thank you!

Hey @Havock94!

You can store it as a static data. You can read about it here: Function | Docs.

However, it is not advisable to store huge amount of static data.

Thanks, I missed it!
Since my data is quite big I decided to use Redis, splitting the data into keys and then read the data by accessing one key at a time.

1 Like

Just as a note if anyone is doing something similar, this is the resulting workflow.

The Redis info node returns the number of keys for each DB.
In my case, I check if the DB is already populated: if not, read the file from FS and populate the DB with a key for each entry (I used a string like city1234 as key).
In case the keys are already there, I just get a random key with the get node, calculating a random key with 'city' + Math.random() * $json.db0.keys.

This way the first execution takes around 10 seconds (read file from FS, convert binary to JSON, populate Redis DB), but every execution after that is basically instant!

2 Likes

Amazing, I was looking for exactly that to use in my WhatsApp system and it worked out really well! thank you so much man :star_struck:

3 Likes