Comparing version 3.0.1 to 4.0.0
@@ -0,1 +1,6 @@ | ||
4.0.0 | ||
----- | ||
* Recompiled using cs 1.9.1 - @jkrems #11 | ||
* Bringing this package into the future, io.js support - @jkrems #10 | ||
v3.0.1 | ||
@@ -2,0 +7,0 @@ ------ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,14 +34,13 @@ /* | ||
*/ | ||
var backend, typeMap; | ||
'use strict'; | ||
var typeMap; | ||
backend = module.exports = {}; | ||
typeMap = Object.create(null); | ||
typeMap = {}; | ||
backend.addType = function(type, klass) { | ||
exports.addType = function(type, klass) { | ||
return typeMap[type] = klass; | ||
}; | ||
backend.create = function(options) { | ||
var klass, type, _ref; | ||
exports.create = function(options) { | ||
var klass, ref, type; | ||
if (options == null) { | ||
@@ -53,6 +52,6 @@ options = {}; | ||
} | ||
type = (_ref = options.type) != null ? _ref : 'noop'; | ||
type = (ref = options.type) != null ? ref : 'noop'; | ||
klass = typeMap[type]; | ||
if (klass == null) { | ||
throw new Error("" + type + " is not a supported cache backend type"); | ||
throw new Error(type + " is not a supported cache backend type"); | ||
} | ||
@@ -62,6 +61,6 @@ return new klass(options); | ||
backend.addType('noop', require("./backends/noop")); | ||
exports.addType('noop', require("./backends/noop")); | ||
backend.addType('memory', require("./backends/memory")); | ||
exports.addType('memory', require("./backends/memory")); | ||
backend.addType('memcached', require("./backends/memcached")); | ||
exports.addType('memcached', require("./backends/memcached")); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,6 +34,9 @@ /* | ||
*/ | ||
var Memcached, MemcachedBackend; | ||
'use strict'; | ||
var Memcached, MemcachedBackend, promisify; | ||
Memcached = require('memcached'); | ||
promisify = require('bluebird').promisify; | ||
MemcachedBackend = (function() { | ||
@@ -45,3 +48,3 @@ var description; | ||
function MemcachedBackend(options) { | ||
var hosts, _ref; | ||
var hosts, ref; | ||
this.type = 'memcached'; | ||
@@ -51,16 +54,16 @@ if (options.client != null) { | ||
} else { | ||
hosts = (_ref = options.hosts) != null ? _ref : '127.0.0.1:11211'; | ||
hosts = (ref = options.hosts) != null ? ref : '127.0.0.1:11211'; | ||
this.client = new Memcached(hosts, options); | ||
} | ||
this._clientGet = promisify(this.client.get, this.client); | ||
this._clientSet = promisify(this.client.set, this.client); | ||
this._clientDel = promisify(this.client.del, this.client); | ||
} | ||
MemcachedBackend.prototype.get = function(key, callback) { | ||
return this.client.get(key, function(err, answer) { | ||
MemcachedBackend.prototype.get = function(key) { | ||
return this._clientGet(key).then(function(answer) { | ||
if (answer === false) { | ||
answer = null; | ||
} | ||
if (err != null) { | ||
return callback(err); | ||
return null; | ||
} else { | ||
return callback(null, answer); | ||
return answer; | ||
} | ||
@@ -70,18 +73,12 @@ }); | ||
MemcachedBackend.prototype.set = function(key, value, options, callback) { | ||
return this.client.set(key, value, options.expire, function(err, ok) { | ||
if (err != null) { | ||
return callback(err); | ||
} else { | ||
return callback(null, value); | ||
} | ||
MemcachedBackend.prototype.set = function(key, value, options) { | ||
return this._clientSet(key, value, options.expire).then(function() { | ||
return value; | ||
}); | ||
}; | ||
MemcachedBackend.prototype.unset = function(key, callback) { | ||
delete this.cache[key]; | ||
if (callback != null) { | ||
callback(null); | ||
} | ||
return null; | ||
MemcachedBackend.prototype.unset = function(key) { | ||
return this._clientDel(key).then(function() { | ||
return void 0; | ||
}); | ||
}; | ||
@@ -88,0 +85,0 @@ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,4 +34,7 @@ /* | ||
*/ | ||
var MemoryBackend; | ||
'use strict'; | ||
var MemoryBackend, Promise; | ||
Promise = require('bluebird'); | ||
MemoryBackend = (function() { | ||
@@ -43,15 +46,12 @@ var description; | ||
function MemoryBackend() { | ||
this.cache = {}; | ||
this.cache = Object.create(null); | ||
this.type = 'memory'; | ||
} | ||
MemoryBackend.prototype.get = function(key, callback) { | ||
var _ref, _ref1, _ref2; | ||
if (this.isExpired((_ref = this.cache[key]) != null ? _ref.e : void 0)) { | ||
MemoryBackend.prototype.get = function(key) { | ||
var ref, ref1, ref2; | ||
if (this.isExpired((ref = this.cache[key]) != null ? ref.e : void 0)) { | ||
delete this.cache[key]; | ||
} | ||
if (callback != null) { | ||
callback(null, (_ref1 = (_ref2 = this.cache[key]) != null ? _ref2.d : void 0) != null ? _ref1 : null); | ||
} | ||
return null; | ||
return Promise.resolve((ref1 = (ref2 = this.cache[key]) != null ? ref2.d : void 0) != null ? ref1 : null); | ||
}; | ||
@@ -77,3 +77,3 @@ | ||
MemoryBackend.prototype.set = function(key, value, options, callback) { | ||
MemoryBackend.prototype.set = function(key, value, options) { | ||
this.cache[key] = { | ||
@@ -83,14 +83,8 @@ d: value, | ||
}; | ||
if (callback != null) { | ||
callback(null, value); | ||
} | ||
return null; | ||
return Promise.resolve(value); | ||
}; | ||
MemoryBackend.prototype.unset = function(key, callback) { | ||
MemoryBackend.prototype.unset = function(key) { | ||
delete this.cache[key]; | ||
if (callback != null) { | ||
callback(null); | ||
} | ||
return null; | ||
return Promise.resolve(); | ||
}; | ||
@@ -97,0 +91,0 @@ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,4 +34,7 @@ /* | ||
*/ | ||
var NoopBackend; | ||
'use strict'; | ||
var NoopBackend, Promise; | ||
Promise = require('bluebird'); | ||
NoopBackend = (function() { | ||
@@ -46,12 +49,12 @@ var description; | ||
NoopBackend.prototype.get = function(key, callback) { | ||
return callback(null, null); | ||
NoopBackend.prototype.get = function(key) { | ||
return Promise.resolve(null); | ||
}; | ||
NoopBackend.prototype.set = function(key, value, options, callback) { | ||
return callback(null, value); | ||
NoopBackend.prototype.set = function(key, value) { | ||
return Promise.resolve(value); | ||
}; | ||
NoopBackend.prototype.unset = function(key, callback) { | ||
return callback(null); | ||
NoopBackend.prototype.unset = function(key) { | ||
return Promise.resolve(); | ||
}; | ||
@@ -58,0 +61,0 @@ |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,7 +34,8 @@ /* | ||
*/ | ||
var Backend, Cache, Q, expiresAt, extend, isExpired, optionalOpts, toPromise; | ||
'use strict'; | ||
var Backend, Cache, Promise, expiresAt, extend, isExpired, optionalOpts, toPromise; | ||
extend = require('lodash').extend; | ||
Q = require('q'); | ||
Promise = require('bluebird'); | ||
@@ -45,5 +46,5 @@ Backend = require('./backend'); | ||
if ('function' === typeof val) { | ||
return Q(val()); | ||
return Promise.resolve(val()); | ||
} else { | ||
return Q(val); | ||
return Promise.resolve(val); | ||
} | ||
@@ -82,5 +83,5 @@ }; | ||
Cache = (function() { | ||
function Cache(_arg) { | ||
function Cache(arg) { | ||
var backend, defaults, name; | ||
backend = _arg.backend, defaults = _arg.defaults, name = _arg.name; | ||
backend = arg.backend, defaults = arg.defaults, name = arg.name; | ||
this.defaults = { | ||
@@ -91,3 +92,3 @@ freshFor: 0, | ||
this.name = name || 'default'; | ||
this.prefix = "" + this.name + ":"; | ||
this.prefix = this.name + ":"; | ||
this.staleOrPending = {}; | ||
@@ -115,4 +116,4 @@ this.setDefaults(defaults); | ||
Cache.prototype.end = function() { | ||
var _ref; | ||
if (((_ref = this.backend) != null ? _ref.end : void 0) != null) { | ||
var ref; | ||
if (((ref = this.backend) != null ? ref.end : void 0) != null) { | ||
return this.backend.end(); | ||
@@ -127,19 +128,18 @@ } | ||
Cache.prototype.set = function(key, val, opts, cb) { | ||
var backend, _ref; | ||
_ref = optionalOpts(opts, cb), cb = _ref.cb, opts = _ref.opts; | ||
var ref; | ||
ref = optionalOpts(opts, cb), cb = ref.cb, opts = ref.opts; | ||
key = this.applyPrefix(key); | ||
backend = this.backend; | ||
opts = this.prepareOptions(opts); | ||
return toPromise(val).then(function(resolvedValue) { | ||
var wrappedValue; | ||
wrappedValue = { | ||
b: expiresAt(opts.freshFor), | ||
d: resolvedValue | ||
return toPromise(val).then((function(_this) { | ||
return function(resolvedValue) { | ||
return _this.backend.set(key, { | ||
b: expiresAt(opts.freshFor), | ||
d: resolvedValue | ||
}, opts); | ||
}; | ||
return Q.npost(backend, 'set', [key, wrappedValue, opts]); | ||
}).nodeify(cb); | ||
})(this)).nodeify(cb); | ||
}; | ||
Cache.prototype.getWrapped = function(key) { | ||
return Q.npost(this.backend, 'get', [key]); | ||
return this.backend.get(key); | ||
}; | ||
@@ -151,4 +151,4 @@ | ||
return this.getWrapped(key).then(function(wrappedValue) { | ||
var _ref; | ||
return (_ref = wrappedValue != null ? wrappedValue.d : void 0) != null ? _ref : null; | ||
var ref; | ||
return (ref = wrappedValue != null ? wrappedValue.d : void 0) != null ? ref : null; | ||
}).nodeify(cb); | ||
@@ -158,5 +158,5 @@ }; | ||
Cache.prototype.getOrElse = function(rawKey, val, opts, cb) { | ||
var handleError, key, refreshValue, verifyFreshness, _ref; | ||
var handleError, key, ref, refreshValue, verifyFreshness; | ||
key = this.applyPrefix(rawKey); | ||
_ref = optionalOpts(opts, cb), cb = _ref.cb, opts = _ref.opts; | ||
ref = optionalOpts(opts, cb), cb = ref.cb, opts = ref.opts; | ||
opts = this.prepareOptions(opts); | ||
@@ -168,5 +168,5 @@ refreshValue = (function(_this) { | ||
return _this.set(rawKey, generatedValue, opts).then(function(rawValue) { | ||
var _ref1; | ||
var ref1; | ||
delete _this.staleOrPending[key]; | ||
return (_ref1 = rawValue != null ? rawValue.d : void 0) != null ? _ref1 : null; | ||
return (ref1 = rawValue != null ? rawValue.d : void 0) != null ? ref1 : null; | ||
}, function(err) { | ||
@@ -180,3 +180,3 @@ delete _this.staleOrPending[key]; | ||
return function(wrappedValue) { | ||
var expired, hit, loadingNewValue, _ref1; | ||
var expired, hit, loadingNewValue, ref1; | ||
hit = wrappedValue != null; | ||
@@ -188,3 +188,3 @@ expired = isExpired(wrappedValue != null ? wrappedValue.b : void 0); | ||
} | ||
return (_ref1 = wrappedValue != null ? wrappedValue.d : void 0) != null ? _ref1 : _this.staleOrPending[key]; | ||
return (ref1 = wrappedValue != null ? wrappedValue.d : void 0) != null ? ref1 : _this.staleOrPending[key]; | ||
}; | ||
@@ -191,0 +191,0 @@ })(this); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.1 | ||
@@ -34,17 +34,13 @@ /* | ||
*/ | ||
var Cache, Q, cached, extend, namedCaches; | ||
'use strict'; | ||
var Cache, Promise, cached, extend, namedCaches; | ||
try { | ||
Q = require('../node_modules/q'); | ||
Q.stopUnhandledRejectionTracking(); | ||
} catch (_error) { | ||
Q = require('q'); | ||
} | ||
Promise = require('bluebird'); | ||
extend = require('lodash').extend; | ||
Cache = require('./cache'); | ||
extend = require('lodash').extend; | ||
namedCaches = Object.create(null); | ||
namedCaches = {}; | ||
cached = function(name, options) { | ||
@@ -71,3 +67,3 @@ if (name == null) { | ||
cached.dropNamedCaches = function() { | ||
namedCaches = {}; | ||
namedCaches = Object.create(null); | ||
return cached; | ||
@@ -86,7 +82,5 @@ }; | ||
cached.deferred = function(fn) { | ||
return function() { | ||
return Q.nfcall(fn); | ||
}; | ||
return Promise.promisify(fn); | ||
}; | ||
module.exports = cached; |
{ | ||
"name": "cached", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Simple access to a cache", | ||
@@ -12,3 +12,8 @@ "main": "lib/cached.js", | ||
"scripts": { | ||
"test": "make test" | ||
"build": "coffee -cbo lib src", | ||
"watch": "coffee -wcbo lib src", | ||
"prepublish": "rm -rf lib && npm run build", | ||
"pretest": "npm run build", | ||
"test": "mocha", | ||
"posttest": "npub verify" | ||
}, | ||
@@ -33,13 +38,12 @@ "repository": { | ||
"dependencies": { | ||
"lodash": "~2.4.1", | ||
"memcached": "~2.0.0", | ||
"q": "~0.9.7" | ||
"bluebird": "^2.9.7", | ||
"lodash": "^3.1.0", | ||
"memcached": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"bondjs": "~1.0.0", | ||
"coffee-script": "~1.8.0", | ||
"expect.js": "~0.2.0", | ||
"mocha": "~2.0.1", | ||
"npub": "0.0.5" | ||
"assertive": "^1.4.1", | ||
"coffee-script": "^1.9.0", | ||
"mocha": "^2.0.1", | ||
"npub": "~0.5.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
28704
14
476
+ Addedbluebird@^2.9.7
+ Addedbluebird@2.11.0(transitive)
+ Addedhashring@3.2.0(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedmemcached@2.2.2(transitive)
- Removedq@~0.9.7
- Removedbindings@1.2.1(transitive)
- Removedhashring@3.0.0(transitive)
- Removedlodash@2.4.2(transitive)
- Removedmemcached@2.0.0(transitive)
- Removednan@1.3.0(transitive)
- Removedq@0.9.7(transitive)
Updatedlodash@^3.1.0
Updatedmemcached@^2.1.0