SailsJS Override Methods

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) // No cache data
      // get the data and return it
    else
      // return the cache data
  });
}

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?

+4
source share
1

- , Waterline, , , - . find findOne , "" , , .

(, sails-mysql) Redis, , , . , ( ) , , , . - , ! IRC Sails (irc://irc.freenode.net/sailsjs), , - - .

+1

Source: https://habr.com/ru/post/1539270/


All Articles