diff --git a/lib/index.js b/lib/index.js index 71948a0..4aa4b02 100644 --- a/lib/index.js +++ b/lib/index.js @@ -44,7 +44,10 @@ Cacher.prototype.prefix = function prefix(cachePrefix) { */ Cacher.prototype.run = function run(options) { this.options = options || this.options; - return this.fetchFromCache(); + + return redis.ready + ? this.fetchFromCache() + : this.fetchFromDatabase(this.options.key, true); }; /** @@ -124,8 +127,8 @@ Cacher.prototype.ttl = function ttl(seconds) { /** * Fetch from the database */ -Cacher.prototype.fetchFromDatabase = function fetchFromDatabase(key) { - var method = this.md[this.method]; +Cacher.prototype.fetchFromDatabase = function fetchFromDatabase(key, nocache) { + var method = this.model[this.method]; var self = this; this.cacheHit = false; return new Promise(function promiser(resolve, reject) { @@ -144,6 +147,10 @@ Cacher.prototype.fetchFromDatabase = function fetchFromDatabase(key) { } else { res = results; } + + if (nocache) + return resolve(res); + return self.setCache(key, res, self.seconds) .then( function good() {