Tuesday, February 16, 2021

Nodejs Data Caching with Redis Part 2: Ultimate Way

I have shown an example of a direct approach on how to use Redis on NodeJS in Part 1. The disadvantage of the direct approach is redundant code where you have to initial Redis Server and to check whether there is a cache whenever you use it.

In this part 2, I am going to centralise the intitial Redis Server and add new method in mongoose:

.cache() = Cache value into redis memory database.

clearCache() = Delete value from redis memory database.

You can download the code at https://github.com/htsiah/node-redis-mongodb

The Redis Code store in utils/useCacheUtil.js and the sample code at controllers/TeacherController.js

No comments:

Post a Comment