I add caching (redis) to my project and prefer to encode it into the model logic rather than the controller. I will need to overwrite the model method and add the logic for caching there.
I know that I can override some methods, such as findand findOne, but I'm not sure what to return.
Example (pseudo)
findOne: function () {
cache.get(key, function (err, data) {
if (data === null)
else
});
}
The problem is that these model methods not only return data, they return an instance of the model itself (for the chain).
Not sure how to return the data and how to get it if it is not already installed. Has anyone ever done anything like this?
source
share