DEV Community

Discussion on: Is writing to JSON an acceptable cache

Collapse
 
rhymes profile image
rhymes • Edited

It seems what you're asking is a normal cache. Get the response, put it in a Redis instance and set a 24h expiration time.

From your web app get the cached data, if the cache is empty, go back to the API, get the response, fill the cache and serve it to the client.

It could be as simple as that.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Sounds about right, I have implemented something close to this idea in a JSON cache where file names are dated.

Collapse
 
rhymes profile image
rhymes

You can also use the disk if you don't want to setup Redis and if you have access to the file system.

A cache is a cache. There are advantages and disadvantages on each cache but you can totally start with a json file on disk and then move on something more scalable if you need to.

The principle is the same, replace Redis with the file. Keep in mind that you need to cleanup the cache manually at some point, though one file per day isn't too much