My approach is as follow:
Pretty basic one, what are the other techniques involved? How to decide the time for expiry of cache?
Note : I am using MySQL for persisting data
You can set expiration of individual keys by using EXPIRE.
EXPIRE key 10
There can be multiple scenarios in which you want to use EXPIRE.
Here's the full documentation redis.io/commands/expire
Sarath C
Head of Engineering at a Digital Health Startup
If you are using ExpressJS as your web framework, you can add middle-ware functions to easily handle the caching mechanism with elegant code.
You may use
setexwith an expiry value and add a middleware as give below for the request.app.get('/repos', cache, getNumberOfRepos);You may use native redis package to initialize connection
An Example middleware function is given below
function cache(req, res, next) { const org = req.query.org; client.get(org, function (err, data) { if (err) throw err; if (data != null) { res.send(respond(org, data)); } else { next(); } }); }Try this out: community.risingstack.com/redis-node-js-introduct…