【发布时间】:2014-06-21 16:36:13
【问题描述】:
我正在将缓存 (redis) 添加到我的项目中,并且更愿意将其编码到模型逻辑而不是控制器中。我需要覆盖模型方法并在那里添加缓存逻辑。
我知道我可以覆盖某些方法,例如 find 和 findOne,但我不确定要返回什么。
示例(伪)
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
});
}
问题在于这些模型方法不只是返回数据,它们返回模型本身的一个实例(用于链接)。
不确定如何返回数据以及如何获取数据(如果尚未设置)。有没有人做过这样的事情?
【问题讨论】:
标签: javascript node.js caching redis sails.js