Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down