Skip to content

Commit

Permalink
explore caching w/ redis StephenGrider#2
Browse files Browse the repository at this point in the history
  • Loading branch information
przemwierzbicki committed Dec 1, 2019
1 parent 6e00812 commit 9d31e80
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions routes/blogRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 9d31e80

Please sign in to comment.