diff --git a/routes/blogRoutes.js b/routes/blogRoutes.js index f0bce864..67ccd8fe 100644 --- a/routes/blogRoutes.js +++ b/routes/blogRoutes.js @@ -22,8 +22,16 @@ module.exports = app => { const cachedBlogs = await client.get(req.user.id); + if (cachedBlogs) { + console.log('serving from cache'); + return res.send(JSON.parse(cachedBlogs)); + } + + console.log('serving from mongodb'); const blogs = await Blog.find({ _user: req.user.id }); + client.set(req.user.id, JSON.stringify(blogs)); + res.send(blogs); });