Nusha Nusha - 1 year ago 58
Javascript Question

Best way to cache data on node js

I have Json file I need to look for specific value (file is pretty big) and I want to turn this json into array so doing so would be easier and faster.
BUT what is the best way to save this array? so I wont need to run over this json every time and it will be saved until recycle or service restart?
(node js project)

Answer Source

1) Use Redis recommended


  1. Access objects super fast.
  2. Isolated from node process.
    • Will not affect heap memory.
    • Can be deployed at separated server.
    • Data persistence if your application crashed.
  3. Support compression.
    • low memory consumption.


  1. You may face some limitations if you have nested objects, but there is a workaround which requires extra work to handle.

2) Use database preferred MongoDB,


  1. Save/Load objects easily since MongoDB supports JSON.
  2. The same as number 2 of Redis pros


  1. You have to query every time to access objects.

3) Use Files not recommended, When your application start/restart, load your objects form file into global array, and when close/shutdown your application dump your objects from global array back into file.


  1. Access objects fast.


  1. Heap memory leakage if your objects size are Huge.
  2. Data loss if your application crashed.

At the end it's your choice, if the speed matters choose Redis, if you want the easy way choose mongoDB. If it's not a problem losing some of your data go for Files. Also you can mix between number 2 and 3.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download