Comparing version 4.3.1 to 4.3.2
@@ -0,1 +1,7 @@ | ||
### 4.3.2 | ||
* Apply latest nlm generator - **[@markowsiak](https://github.com/markowsiak)** [#38](https://github.com/groupon/node-cached/pull/38) | ||
- [`35b216e`](https://github.com/groupon/node-cached/commit/35b216e3d11b94502d968d40fcf7f34e7a5b507e) **chore:** Apply latest nlm generator | ||
### 4.3.1 | ||
@@ -2,0 +8,0 @@ |
@@ -32,5 +32,6 @@ /* | ||
*/ | ||
'use strict'; | ||
var typeMap = Object.create(null); | ||
const typeMap = Object.create(null); | ||
@@ -48,6 +49,6 @@ function isBackend(object) { | ||
var type = options.type || 'noop'; | ||
var BackendClass = typeMap[type]; | ||
const type = options.type || 'noop'; | ||
const BackendClass = typeMap[type]; | ||
if (!BackendClass) { | ||
throw new Error(type + ' is not a supported cache backend type'); | ||
throw new Error(`${type} is not a supported cache backend type`); | ||
} | ||
@@ -54,0 +55,0 @@ return new BackendClass(options); |
@@ -32,7 +32,8 @@ /* | ||
*/ | ||
'use strict'; | ||
var promisify = require('bluebird').promisify; | ||
var _ = require('lodash'); | ||
var Memcached = require('memcached'); | ||
const promisify = require('bluebird').promisify; | ||
const _ = require('lodash'); | ||
const Memcached = require('memcached'); | ||
@@ -43,3 +44,3 @@ function createClient(options) { | ||
} | ||
var hosts = options.hosts || '127.0.0.1:11211'; | ||
const hosts = options.hosts || '127.0.0.1:11211'; | ||
return new Memcached(hosts, options); | ||
@@ -55,3 +56,3 @@ } | ||
this.type = 'memcached'; | ||
var client = this.client = createClient(options); | ||
const client = (this.client = createClient(options)); | ||
this._clientGet = promisify(client.get, { context: client }); | ||
@@ -68,4 +69,3 @@ this._clientSet = promisify(client.set, { context: client }); | ||
MemcachedBackend.prototype.set = function set(key, value, options) { | ||
return this._clientSet(key, value, options.expire) | ||
.then(_.constant(value)); | ||
return this._clientSet(key, value, options.expire).then(_.constant(value)); | ||
}; | ||
@@ -72,0 +72,0 @@ |
@@ -32,7 +32,8 @@ /* | ||
*/ | ||
'use strict'; | ||
var Bluebird = require('bluebird'); | ||
const Bluebird = require('bluebird'); | ||
var util = require('../util'); | ||
const util = require('../util'); | ||
@@ -47,3 +48,3 @@ /* Stores everything just in memory */ | ||
MemoryBackend.prototype.get = function get(key) { | ||
var wrappedValue = this.cache[key] || null; | ||
let wrappedValue = this.cache[key] || null; | ||
if (util.isExpired(wrappedValue && wrappedValue.e)) { | ||
@@ -50,0 +51,0 @@ wrappedValue = null; |
@@ -32,5 +32,6 @@ /* | ||
*/ | ||
'use strict'; | ||
var Bluebird = require('bluebird'); | ||
const Bluebird = require('bluebird'); | ||
@@ -37,0 +38,0 @@ /* Simple backend doing nothing */ |
@@ -32,9 +32,12 @@ /* | ||
*/ | ||
/* eslint-disable no-underscore-dangle */ | ||
'use strict'; | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
var Backend = require('./backend'); | ||
var getOrElse = require('./get-or-else'); | ||
var util = require('./util'); | ||
const Backend = require('./backend'); | ||
const getOrElse = require('./get-or-else'); | ||
const util = require('./util'); | ||
@@ -47,3 +50,3 @@ function Cache(options) { | ||
this.name = options.name || 'default'; | ||
this.prefix = this.name + ':'; | ||
this.prefix = `${this.name}:`; | ||
this.staleOrPending = {}; | ||
@@ -65,5 +68,8 @@ | ||
Cache.prototype.setBackend = function setBackend(backendOptions) { | ||
backendOptions = typeof backendOptions === 'string' ? { | ||
type: backendOptions, | ||
} : backendOptions || {}; | ||
backendOptions = | ||
typeof backendOptions === 'string' | ||
? { | ||
type: backendOptions, | ||
} | ||
: backendOptions || {}; | ||
this.end(); | ||
@@ -85,8 +91,12 @@ this.backend = Backend.create(backendOptions); | ||
Cache.prototype._set = function _set(key, val, options) { | ||
var self = this; | ||
const self = this; | ||
function writeToBackend(resolvedValue) { | ||
return self.backend.set(key, { | ||
b: util.expiresAt(options.freshFor), | ||
d: resolvedValue, | ||
}, options); | ||
return self.backend.set( | ||
key, | ||
{ | ||
b: util.expiresAt(options.freshFor), | ||
d: resolvedValue, | ||
}, | ||
options | ||
); | ||
} | ||
@@ -98,5 +108,5 @@ | ||
Cache.prototype.set = function set(rawKey, val, _opts, _cb) { | ||
var args = util.optionalOpts(_opts, _cb); | ||
var key = this.applyPrefix(rawKey); | ||
var optsWithDefaults = this.prepareOptions(args.opts); | ||
const args = util.optionalOpts(_opts, _cb); | ||
const key = this.applyPrefix(rawKey); | ||
const optsWithDefaults = this.prepareOptions(args.opts); | ||
@@ -107,3 +117,3 @@ return this._set(key, val, optsWithDefaults).nodeify(args.cb); | ||
Cache.prototype._applyTimeout = function _applyTimeout(value) { | ||
var timeoutMs = this.defaults.timeout; | ||
const timeoutMs = this.defaults.timeout; | ||
if (timeoutMs > 0) { | ||
@@ -123,11 +133,13 @@ return value.timeout(timeoutMs); | ||
Cache.prototype.get = function get(rawKey, cb) { | ||
var key = this.applyPrefix(rawKey); | ||
const key = this.applyPrefix(rawKey); | ||
return this._getWrapped(key).then(util.extractValue).nodeify(cb); | ||
return this._getWrapped(key) | ||
.then(util.extractValue) | ||
.nodeify(cb); | ||
}; | ||
Cache.prototype.getOrElse = function _getOrElse(rawKey, val, _opts, _cb) { | ||
var key = this.applyPrefix(rawKey); | ||
var args = util.optionalOpts(_opts, _cb); | ||
var optsWithDefaults = this.prepareOptions(args.opts); | ||
const key = this.applyPrefix(rawKey); | ||
const args = util.optionalOpts(_opts, _cb); | ||
const optsWithDefaults = this.prepareOptions(args.opts); | ||
@@ -138,3 +150,3 @@ return getOrElse(this, key, val, optsWithDefaults).nodeify(args.cb); | ||
Cache.prototype.unset = function unset(rawKey, cb) { | ||
var key = this.applyPrefix(rawKey); | ||
const key = this.applyPrefix(rawKey); | ||
@@ -141,0 +153,0 @@ return this._unset(key).nodeify(cb); |
@@ -32,13 +32,14 @@ /* | ||
*/ | ||
'use strict'; | ||
var Bluebird = require('bluebird'); | ||
var _ = require('lodash'); | ||
var util = require('util'); | ||
const Bluebird = require('bluebird'); | ||
const _ = require('lodash'); | ||
const util = require('util'); | ||
var Cache = require('./cache'); | ||
const Cache = require('./cache'); | ||
var namedCaches = Object.create(null); | ||
let namedCaches = Object.create(null); | ||
var getName = util.deprecate(function getName(name) { | ||
const getName = util.deprecate(function getName(name) { | ||
return name || 'default'; | ||
@@ -53,5 +54,10 @@ }, 'Unnamed caches and caches with non-string names are deprecated.'); | ||
if (!(name in namedCaches)) { | ||
namedCaches[name] = cached.createCache(_.extend({ | ||
name: name, | ||
}, options || {})); | ||
namedCaches[name] = cached.createCache( | ||
_.extend( | ||
{ | ||
name: name, | ||
}, | ||
options || {} | ||
) | ||
); | ||
} | ||
@@ -58,0 +64,0 @@ return namedCaches[name]; |
@@ -32,8 +32,11 @@ /* | ||
*/ | ||
/* eslint-disable no-underscore-dangle */ | ||
'use strict'; | ||
var Bluebird = require('bluebird'); | ||
var _ = require('lodash'); | ||
const Bluebird = require('bluebird'); | ||
const _ = require('lodash'); | ||
var util = require('./util'); | ||
const util = require('./util'); | ||
@@ -51,3 +54,4 @@ function getOrElse(cache, key, val, opts) { | ||
return cache._set(key, generatedValue, opts) | ||
return cache | ||
._set(key, generatedValue, opts) | ||
.then(util.extractValue) | ||
@@ -58,3 +62,3 @@ .catch(fallbackToLoadedValue); | ||
function refreshValue() { | ||
var refreshed; | ||
let refreshed; | ||
@@ -69,3 +73,4 @@ function handleWriteError(err) { | ||
refreshed = util.toPromise(val) | ||
refreshed = util | ||
.toPromise(val) | ||
.then(writeValue) | ||
@@ -78,5 +83,5 @@ .then(resetStaleOrPending, handleWriteError); | ||
function verifyFreshness(wrappedValue) { | ||
var hit = !!wrappedValue; | ||
var expired = util.isExpired(wrappedValue && wrappedValue.b); | ||
var loadingNewValue = cache.staleOrPending[key] !== undefined; | ||
const hit = !!wrappedValue; | ||
const expired = util.isExpired(wrappedValue && wrappedValue.b); | ||
let loadingNewValue = cache.staleOrPending[key] !== undefined; | ||
@@ -88,4 +93,4 @@ if ((!hit || expired) && !loadingNewValue) { | ||
var dataFromCache = util.extractValue(wrappedValue); | ||
if ((dataFromCache === null) && loadingNewValue) { | ||
const dataFromCache = util.extractValue(wrappedValue); | ||
if (dataFromCache === null && loadingNewValue) { | ||
cache.staleOrPending[key].wasEverReturned = true; | ||
@@ -98,3 +103,4 @@ return cache.staleOrPending[key]; | ||
return cache._getWrapped(key) | ||
return cache | ||
._getWrapped(key) | ||
.catch(_.constant(null)) | ||
@@ -101,0 +107,0 @@ .then(verifyFreshness); |
@@ -32,5 +32,6 @@ /* | ||
*/ | ||
'use strict'; | ||
var Bluebird = require('bluebird'); | ||
const Bluebird = require('bluebird'); | ||
@@ -52,3 +53,3 @@ exports.expiresAt = function expiresAt(seconds) { | ||
exports.extractValue = function extractValue(wrappedValue) { | ||
var value = wrappedValue && wrappedValue.d; | ||
const value = wrappedValue && wrappedValue.d; | ||
// Normalize `undefined` into `null` | ||
@@ -55,0 +56,0 @@ return value === undefined ? null : value; |
{ | ||
"name": "cached", | ||
"version": "4.3.1", | ||
"version": "4.3.2", | ||
"description": "Simple access to a cache", | ||
@@ -10,3 +10,3 @@ "license": "BSD-3-Clause", | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/groupon/node-cached" | ||
"url": "https://github.com/groupon/node-cached" | ||
}, | ||
@@ -35,8 +35,15 @@ "bugs": { | ||
"devDependencies": { | ||
"assertive": "^2.0.0", | ||
"assertive": "^2.1.0", | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^5.8.33", | ||
"eslint": "^1.0.0", | ||
"eslint-config-groupon": "^2.0.0", | ||
"mocha": "^2.0.0", | ||
"nlm": "^2.0.0" | ||
"babel-eslint": "^8.1.2", | ||
"babel-preset-env": "^1.6.0", | ||
"eslint": "^4.7.1", | ||
"eslint-config-groupon": "^5.0.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-prettier": "^2.2.0", | ||
"mocha": "^3.1.2", | ||
"nlm": "^3.0.0", | ||
"prettier": "^1.6.1" | ||
}, | ||
@@ -43,0 +50,0 @@ "author": { |
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
36384
577
13