exp-asynccache
Advanced tools
Comparing version
80
index.js
@@ -22,2 +22,78 @@ "use strict"; | ||
AsyncCache.prototype.get = function (key, callback) { | ||
return Promise.resolve(this.cache.get(key)).then(function (data) { | ||
if (typeof callback === "function") { | ||
callback(null, data); | ||
} | ||
return data; | ||
}, function (err) { | ||
if (typeof callback === "function") { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
AsyncCache.prototype.has = function (key, callback) { | ||
return Promise.resolve(this.cache.has(key)).then(function (exists) { | ||
if (typeof callback === "function") { | ||
callback(null, exists); | ||
} | ||
return exists; | ||
}, function (err) { | ||
if (typeof callback === "function") { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
AsyncCache.prototype.set = function (key, value, maxAge, callback) { | ||
if (typeof maxAge === "function") { | ||
callback = maxAge; | ||
maxAge = null; | ||
} | ||
return Promise.resolve(this.cache.set(key, value, maxAge)).then(function () { | ||
if (typeof callback === "function") { | ||
callback(); | ||
} | ||
}, function (err) { | ||
if (typeof callback === "function") { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
AsyncCache.prototype.del = function (key, callback) { | ||
return Promise.resolve(this.cache.del(key)).then(function () { | ||
if (typeof callback === "function") { | ||
callback(); | ||
} | ||
}, function (err) { | ||
if (typeof callback === "function") { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
AsyncCache.prototype.reset = function (callback) { | ||
return Promise.resolve(this.cache.reset()).then(function () { | ||
if (typeof callback === "function") { | ||
callback(); | ||
} | ||
}, function (err) { | ||
if (typeof callback === "function") { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}; | ||
AsyncCache.prototype.lookup = function (key, resolveFn, hitFn) { | ||
@@ -30,4 +106,4 @@ var self = this; | ||
function set() { | ||
return Promise.resolve(self.cache.set.apply(self.cache, arguments)); | ||
function set(key, value, maxAge) { | ||
return Promise.resolve(self.cache.set(key, value, maxAge)); | ||
} | ||
@@ -34,0 +110,0 @@ |
{ | ||
"name": "exp-asynccache", | ||
"description": " A small async cache", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "AB Kvällstidningen Expressen", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8364
26.78%166
74.74%0
-100%