Comparing version 6.0.0 to 7.0.0
@@ -1,18 +0,19 @@ | ||
// After starting this example load http://localhost:8080 and hit refresh, you will notice that it loads the response from cache for the first 5 seconds and then reloads the cache. Look at the console to see it setting and getting items from cache. | ||
'use strict'; | ||
// Load modules | ||
var Catbox = require('../'); | ||
var Http = require('http'); | ||
const Catbox = require('../'); | ||
const Http = require('http'); | ||
// Declare internals | ||
var internals = {}; | ||
const internals = {}; | ||
// After starting this example load http://localhost:8080 and hit refresh, you will notice that it loads the response from cache for the first 5 seconds and then reloads the cache. Look at the console to see it setting and getting items from cache. | ||
internals.handler = function (req, res) { | ||
internals.getResponse(function (item) { | ||
internals.getResponse((item) => { | ||
@@ -33,11 +34,11 @@ res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
var clientOptions = { | ||
const clientOptions = { | ||
partition: 'examples' // For redis this will store items under keys that start with examples: | ||
}; | ||
var policyOptions = { | ||
const policyOptions = { | ||
expiresIn: 5000, | ||
generateFunc: function (id, next) { | ||
var item = 'example'; | ||
const item = 'example'; | ||
console.log(item); | ||
@@ -48,4 +49,4 @@ return next(null, item); | ||
var client = new Catbox.Client(require('../test/import'), clientOptions); | ||
client.start(function () { | ||
const client = new Catbox.Client(require('../test/import'), clientOptions); | ||
client.start(() => { | ||
@@ -60,3 +61,3 @@ internals.policy = new Catbox.Policy(policyOptions, client, 'example'); | ||
var server = Http.createServer(internals.handler); | ||
const server = Http.createServer(internals.handler); | ||
server.listen(8080); | ||
@@ -63,0 +64,0 @@ console.log('Server started at http://localhost:8080/'); |
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
var Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
const Boom = require('boom'); | ||
@@ -9,3 +11,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -20,3 +22,3 @@ | ||
Hoek.assert(this.constructor === internals.Client, 'Cache client must be instantiated using new'); | ||
Hoek.assert(this instanceof internals.Client, 'Cache client must be instantiated using new'); | ||
Hoek.assert(engine, 'Missing catbox client engine'); | ||
@@ -26,3 +28,3 @@ Hoek.assert(typeof engine === 'object' || typeof engine === 'function', 'engine must be an engine object or engine prototype (function)'); | ||
var settings = Hoek.applyToDefaults(internals.defaults, options || {}); | ||
const settings = Hoek.applyToDefaults(internals.defaults, options || {}); | ||
Hoek.assert(settings.partition.match(/^[\w\-]+$/), 'Invalid partition name:' + settings.partition); | ||
@@ -60,4 +62,2 @@ | ||
var self = this; | ||
if (!this.connection.isReady()) { | ||
@@ -77,3 +77,3 @@ // Disconnected | ||
this.connection.get(key, function (err, result) { | ||
this.connection.get(key, (err, result) => { | ||
@@ -93,5 +93,5 @@ if (err) { | ||
var now = Date.now(); | ||
var expires = result.stored + result.ttl; | ||
var ttl = expires - now; | ||
const now = Date.now(); | ||
const expires = result.stored + result.ttl; | ||
const ttl = expires - now; | ||
if (ttl <= 0) { | ||
@@ -104,3 +104,3 @@ // Expired | ||
var cached = { | ||
const cached = { | ||
item: result.item, | ||
@@ -107,0 +107,0 @@ stored: result.stored, |
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Client = require('./client'); | ||
var Policy = require('./policy'); | ||
const Client = require('./client'); | ||
const Policy = require('./policy'); | ||
@@ -9,3 +11,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -12,0 +14,0 @@ |
@@ -0,6 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Boom = require('boom'); | ||
var Hoek = require('hoek'); | ||
var Joi = require('joi'); | ||
const Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
@@ -10,3 +12,3 @@ | ||
var internals = { | ||
const internals = { | ||
day: 24 * 60 * 60 * 1000 | ||
@@ -18,3 +20,3 @@ }; | ||
Hoek.assert(this.constructor === internals.Policy, 'Cache Policy must be instantiated using new'); | ||
Hoek.assert(this instanceof internals.Policy, 'Cache Policy must be instantiated using new'); | ||
@@ -35,3 +37,3 @@ this._cache = cache; | ||
if (cache) { | ||
var nameErr = cache.validateSegmentName(segment); | ||
const nameErr = cache.validateSegmentName(segment); | ||
Hoek.assert(nameErr === null, 'Invalid segment name: ' + segment + (nameErr ? ' (' + nameErr.message + ')' : '')); | ||
@@ -52,4 +54,2 @@ | ||
var self = this; | ||
++this.stats.gets; | ||
@@ -59,4 +59,4 @@ | ||
var id = (key && typeof key === 'object') ? key.id : key; | ||
var pendingsId = '+' + id; // Prefix to avoid conflicts with JS internals (e.g. __proto__) | ||
const id = (key && typeof key === 'object') ? key.id : key; | ||
const pendingsId = '+' + id; // Prefix to avoid conflicts with JS internals (e.g. __proto__) | ||
if (this._pendings[pendingsId]) { | ||
@@ -71,7 +71,7 @@ this._pendings[pendingsId].push(process.domain ? process.domain.bind(callback) : callback); // Explicitly bind callback to its process.domain (_finalize might get called from a different active process.domain) | ||
var timer = new Hoek.Timer(); | ||
this._get(id, function (err, cached) { | ||
const timer = new Hoek.Timer(); | ||
this._get(id, (err, cached) => { | ||
if (err) { | ||
++self.stats.errors; | ||
++this.stats.errors; | ||
} | ||
@@ -81,3 +81,3 @@ | ||
var report = { | ||
const report = { | ||
msec: timer.elapsed(), | ||
@@ -90,3 +90,3 @@ error: err | ||
report.ttl = cached.ttl; | ||
var staleIn = typeof self.rule.staleIn === 'function' ? self.rule.staleIn(cached.stored, cached.ttl) : self.rule.staleIn; | ||
const staleIn = typeof this.rule.staleIn === 'function' ? this.rule.staleIn(cached.stored, cached.ttl) : this.rule.staleIn; | ||
cached.isStale = (staleIn ? (Date.now() - cached.stored) >= staleIn : false); | ||
@@ -96,3 +96,3 @@ report.isStale = cached.isStale; | ||
if (cached.isStale) { | ||
++self.stats.stales; | ||
++this.stats.stales; | ||
} | ||
@@ -103,6 +103,6 @@ } | ||
if (!self.rule.generateFunc || | ||
(err && !self.rule.generateOnReadError)) { | ||
if (!this.rule.generateFunc || | ||
(err && !this.rule.generateOnReadError)) { | ||
return internals.respond(self, id, err, cached ? cached.item : null, cached, report); | ||
return internals.respond(this, id, err, cached ? cached.item : null, cached, report); | ||
} | ||
@@ -115,6 +115,6 @@ | ||
return internals.respond(self, id, null, cached.item, cached, report); | ||
return internals.respond(this, id, null, cached.item, cached, report); | ||
} | ||
return self._generate(id, key, cached, report); | ||
return this._generate(id, key, cached, report); | ||
}); | ||
@@ -126,6 +126,4 @@ }; | ||
var self = this; | ||
const respond = Hoek.once(internals.respond); | ||
var respond = Hoek.once(internals.respond); | ||
if (cached) { // Must be stale | ||
@@ -135,7 +133,7 @@ | ||
cached.ttl -= this.rule.staleTimeout; // Adjust TTL for when the timeout is invoked (staleTimeout must be valid if isStale is true) | ||
cached.ttl = cached.ttl - this.rule.staleTimeout; // Adjust TTL for when the timeout is invoked (staleTimeout must be valid if isStale is true) | ||
if (cached.ttl > 0) { | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
return respond(self, id, null, cached.item, cached, report); | ||
return respond(this, id, null, cached.item, cached, report); | ||
}, this.rule.staleTimeout); | ||
@@ -148,5 +146,5 @@ } | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
return respond(self, id, Boom.serverTimeout(), null, null, report); | ||
return respond(this, id, Boom.serverTimeout(), null, null, report); | ||
}, this.rule.generateTimeout); | ||
@@ -157,18 +155,18 @@ } | ||
++self.stats.generates; // Record generation before call in case it times out | ||
++this.stats.generates; // Record generation before call in case it times out | ||
try { | ||
this.rule.generateFunc.call(null, key, function (generateError, value, ttl) { | ||
this.rule.generateFunc.call(null, key, (generateError, value, ttl) => { | ||
var finalize = function (err) { | ||
const finalize = (err) => { | ||
var error = generateError || (self.rule.generateIgnoreWriteError ? null : err); | ||
const error = generateError || (this.rule.generateIgnoreWriteError ? null : err); | ||
if (cached && | ||
error && | ||
!self.rule.dropOnError) { | ||
!this.rule.dropOnError) { | ||
return respond(self, id, error, cached.item, cached, report); | ||
return respond(this, id, error, cached.item, cached, report); | ||
} | ||
return respond(self, id, error, value, null, report); // Ignored if stale value already returned | ||
return respond(this, id, error, value, null, report); // Ignored if stale value already returned | ||
}; | ||
@@ -178,10 +176,10 @@ | ||
if ((generateError && self.rule.dropOnError) || | ||
if ((generateError && this.rule.dropOnError) || | ||
ttl === 0) { // null or undefined means use policy | ||
return self.drop(id, finalize); // Invalidate cache | ||
return this.drop(id, finalize); // Invalidate cache | ||
} | ||
if (!generateError) { | ||
return self.set(id, value, ttl, finalize); // Lazy save (replaces stale cache copy with late-coming fresh copy) | ||
return this.set(id, value, ttl, finalize); // Lazy save (replaces stale cache copy with late-coming fresh copy) | ||
} | ||
@@ -193,3 +191,3 @@ | ||
catch (err) { | ||
return respond(self, id, err, null, null, report); | ||
return respond(this, id, err, null, null, report); | ||
} | ||
@@ -212,7 +210,7 @@ }; | ||
id = '+' + id; | ||
var pendings = policy._pendings[id]; | ||
const pendings = policy._pendings[id]; | ||
delete policy._pendings[id]; | ||
var length = pendings.length; | ||
for (var i = 0; i < length; ++i) { | ||
const length = pendings.length; | ||
for (let i = 0; i < length; ++i) { | ||
Hoek.nextTick(pendings[i])(err, value, cached, report); | ||
@@ -222,3 +220,3 @@ } | ||
if (report.isStale !== undefined) { | ||
policy.stats.hits += length; | ||
policy.stats.hits = policy.stats.hits + length; | ||
} | ||
@@ -230,7 +228,5 @@ }; | ||
var self = this; | ||
callback = callback || Hoek.ignore; | ||
++self.stats.sets; | ||
++this.stats.sets; | ||
@@ -242,7 +238,7 @@ if (!this._cache) { | ||
ttl = ttl || internals.Policy.ttl(this.rule); | ||
var id = (key && typeof key === 'object') ? key.id : key; | ||
this._cache.set({ segment: this._segment, id: id }, value, ttl, function (err) { | ||
const id = (key && typeof key === 'object') ? key.id : key; | ||
this._cache.set({ segment: this._segment, id: id }, value, ttl, (err) => { | ||
if (err) { | ||
++self.stats.errors; | ||
++this.stats.errors; | ||
} | ||
@@ -257,4 +253,2 @@ | ||
var self = this; | ||
callback = callback || Hoek.ignore; | ||
@@ -266,6 +260,6 @@ | ||
this._cache.drop({ segment: this._segment, id: id }, function (err) { | ||
this._cache.drop({ segment: this._segment, id: id }, (err) => { | ||
if (err) { | ||
++self.stats.errors; | ||
++this.stats.errors; | ||
} | ||
@@ -328,3 +322,3 @@ | ||
var rule = {}; | ||
const rule = {}; | ||
@@ -341,4 +335,4 @@ if (!options || | ||
var hasExpiresIn = options.expiresIn !== undefined && options.expiresIn !== null; | ||
var hasExpiresAt = options.expiresAt !== undefined && options.expiresAt !== null; | ||
const hasExpiresIn = options.expiresIn !== undefined && options.expiresIn !== null; | ||
const hasExpiresAt = options.expiresAt !== undefined && options.expiresAt !== null; | ||
@@ -358,3 +352,3 @@ Hoek.assert(!hasExpiresAt || typeof options.expiresAt === 'string', 'expiresAt must be a string', options); | ||
var time = /^(\d\d?):(\d\d)$/.exec(options.expiresAt); | ||
const time = /^(\d\d?):(\d\d)$/.exec(options.expiresAt); | ||
rule.expiresAt = { | ||
@@ -399,3 +393,3 @@ hours: parseInt(time[1], 10), | ||
created = created || now; | ||
var age = now - created; | ||
const age = now - created; | ||
@@ -415,3 +409,3 @@ if (age < 0) { | ||
var expiresAt = new Date(created); // Compare expiration time on the same day | ||
const expiresAt = new Date(created); // Compare expiration time on the same day | ||
expiresAt.setHours(rule.expiresAt.hours); | ||
@@ -421,9 +415,9 @@ expiresAt.setMinutes(rule.expiresAt.minutes); | ||
expiresAt.setMilliseconds(0); | ||
var expires = expiresAt.getTime(); | ||
let expires = expiresAt.getTime(); | ||
if (expires <= created) { | ||
expires += internals.day; // Move to tomorrow | ||
expires = expires + internals.day; // Move to tomorrow | ||
} | ||
if (now >= expires) { // Expired | ||
if (now >= expires) { // Expired | ||
return 0; | ||
@@ -430,0 +424,0 @@ } |
{ | ||
"name": "catbox", | ||
"description": "Multi-strategy object caching service", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"repository": "git://github.com/hapijs/catbox", | ||
@@ -13,12 +13,12 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.40" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"boom": "2.x.x", | ||
"hoek": "2.x.x", | ||
"joi": "6.x.x" | ||
"boom": "3.x.x", | ||
"hoek": "3.x.x", | ||
"joi": "7.x.x" | ||
}, | ||
"devDependencies": { | ||
"code": "1.x.x", | ||
"lab": "5.x.x" | ||
"code": "2.x.x", | ||
"lab": "7.x.x" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
![catbox Logo](https://raw.github.com/hapijs/catbox/master/images/catbox.png) | ||
Multi-strategy object caching service | ||
Version: **5.x** | ||
Version: **6.x** | ||
@@ -11,3 +11,3 @@ [![Build Status](https://secure.travis-ci.org/hapijs/catbox.png)](http://travis-ci.org/hapijs/catbox) | ||
**catbox** is a multi-strategy key-value object store. It comes with extensions supporting a memory cache, | ||
[Redis](http://redis.io/), [MongoDB](http://www.mongodb.org/), [Memcached](http://memcached.org/), [Riak](http://basho.com/riak/), [Amazon S3](http://aws.amazon.com/s3/), [RethinkDB](http://rethinkdb.com) and [Couchbase](http://www.couchbase.com/). | ||
[Redis](http://redis.io/), [MongoDB](http://www.mongodb.org/), [Memcached](http://memcached.org/), [Riak](http://basho.com/riak/), [Amazon S3](http://aws.amazon.com/s3/), [RethinkDB](http://rethinkdb.com), [Couchbase](http://www.couchbase.com/) and [Aerospike](http://www.aerospike.com/). | ||
**catbox** provides two interfaces: a low-level `Client` and a high-level `Policy`. | ||
@@ -29,2 +29,3 @@ | ||
- [Couchbase](https://github.com/cmfatih/catbox-couchbase) | ||
- [Aerospike](https://github.com/ooogway/catbox-aerospike) | ||
@@ -31,0 +32,0 @@ |
@@ -0,6 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Catbox = require('..'); | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
const Catbox = require('..'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
@@ -10,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -16,24 +18,24 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.experiment; | ||
var it = lab.test; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.experiment; | ||
const it = lab.test; | ||
const expect = Code.expect; | ||
describe('Client', function () { | ||
describe('Client', () => { | ||
it('uses prototype engine', function (done) { | ||
it('uses prototype engine', (done) => { | ||
var Obj = require('./import'); | ||
var client = new Catbox.Client(Obj); | ||
client.start(function (err) { | ||
const Obj = require('./import'); | ||
const client = new Catbox.Client(Obj); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 1000, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 1000, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -48,16 +50,16 @@ expect(err).to.not.exist(); | ||
it('supports empty keys', function (done) { | ||
it('supports empty keys', (done) => { | ||
var Obj = require('./import'); | ||
var client = new Catbox.Client(Obj); | ||
client.start(function (err) { | ||
const Obj = require('./import'); | ||
const client = new Catbox.Client(Obj); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
var key = { id: '', segment: 'test' }; | ||
client.set(key, '123', 1000, function (err) { | ||
const key = { id: '', segment: 'test' }; | ||
client.set(key, '123', 1000, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -72,16 +74,16 @@ expect(err).to.not.exist(); | ||
it('uses object instance engine', function (done) { | ||
it('uses object instance engine', (done) => { | ||
var Obj = require('./import'); | ||
var client = new Catbox.Client(new Obj()); | ||
client.start(function (err) { | ||
const Obj = require('./import'); | ||
const client = new Catbox.Client(new Obj()); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 1000, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 1000, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -96,5 +98,5 @@ expect(err).to.not.exist(); | ||
it('errors when calling get on a bad connection', function (done) { | ||
it('errors when calling get on a bad connection', (done) => { | ||
var errorEngine = { | ||
const errorEngine = { | ||
start: function (callback) { | ||
@@ -127,5 +129,5 @@ | ||
var client = new Catbox.Client(errorEngine); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.get(key, function (err, result) { | ||
const client = new Catbox.Client(errorEngine); | ||
const key = { id: 'x', segment: 'test' }; | ||
client.get(key, (err, result) => { | ||
@@ -138,7 +140,7 @@ expect(err).to.exist(); | ||
describe('start()', function () { | ||
describe('start()', () => { | ||
it('passes an error in the callback when one occurs', function (done) { | ||
it('passes an error in the callback when one occurs', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -150,4 +152,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(engine); | ||
client.start((err) => { | ||
@@ -160,7 +162,7 @@ expect(err).to.exist(); | ||
describe('get()', function () { | ||
describe('get()', () => { | ||
it('returns an error when the connection is not ready', function (done) { | ||
it('returns an error when the connection is not ready', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -176,4 +178,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.get('test', function (err) { | ||
const client = new Catbox.Client(engine); | ||
client.get('test', (err) => { | ||
@@ -186,5 +188,5 @@ expect(err).to.be.instanceOf(Error); | ||
it('wraps the result with cached details', function (done) { | ||
it('wraps the result with cached details', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -200,3 +202,3 @@ | ||
var result = { | ||
const result = { | ||
item: 'test1', | ||
@@ -210,4 +212,4 @@ stored: 'test2' | ||
var client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, function (err, cached) { | ||
const client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, (err, cached) => { | ||
@@ -221,5 +223,5 @@ expect(cached.item).to.equal('test1'); | ||
it('returns nothing when item is not found', function (done) { | ||
it('returns nothing when item is not found', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -239,4 +241,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, function (err, cached) { | ||
const client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, (err, cached) => { | ||
@@ -249,5 +251,5 @@ expect(err).to.equal(null); | ||
it('returns nothing when item is not found (undefined item)', function (done) { | ||
it('returns nothing when item is not found (undefined item)', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -267,4 +269,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, function (err, cached) { | ||
const client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, (err, cached) => { | ||
@@ -277,5 +279,5 @@ expect(err).to.equal(null); | ||
it('returns falsey items', function (done) { | ||
it('returns falsey items', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -298,4 +300,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, function (err, cached) { | ||
const client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, (err, cached) => { | ||
@@ -308,5 +310,5 @@ expect(err).to.equal(null); | ||
it('expires item', function (done) { | ||
it('expires item', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -322,3 +324,3 @@ | ||
var result = { | ||
const result = { | ||
item: 'test1', | ||
@@ -333,4 +335,4 @@ stored: Date.now() - 100, | ||
var client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, function (err, cached) { | ||
const client = new Catbox.Client(engine); | ||
client.get({ id: 'id', segment: 'segment' }, (err, cached) => { | ||
@@ -343,10 +345,10 @@ expect(err).to.equal(null); | ||
it('errors on empty key', function (done) { | ||
it('errors on empty key', (done) => { | ||
var client = new Catbox.Client(require('../test/import')); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(require('../test/import')); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
client.get({}, function (err) { | ||
client.get({}, (err) => { | ||
@@ -361,7 +363,7 @@ expect(err).to.exist(); | ||
describe('set()', function () { | ||
describe('set()', () => { | ||
it('returns an error when the connection is not ready', function (done) { | ||
it('returns an error when the connection is not ready', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -377,4 +379,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.set('test', 'test', 'test', function (err) { | ||
const client = new Catbox.Client(engine); | ||
client.set('test', 'test', 'test', (err) => { | ||
@@ -388,7 +390,7 @@ expect(err).to.be.instanceOf(Error); | ||
describe('drop()', function () { | ||
describe('drop()', () => { | ||
it('calls the extension clients drop function', function (done) { | ||
it('calls the extension clients drop function', (done) => { | ||
var engine = { | ||
const engine = { | ||
start: function (callback) { | ||
@@ -408,4 +410,4 @@ | ||
var client = new Catbox.Client(engine); | ||
client.drop({ id: 'id', segment: 'segment' }, function (err, result) { | ||
const client = new Catbox.Client(engine); | ||
client.drop({ id: 'id', segment: 'segment' }, (err, result) => { | ||
@@ -418,14 +420,14 @@ expect(result).to.equal('success'); | ||
describe('validateKey()', function () { | ||
describe('validateKey()', () => { | ||
it('errors on missing segment', function (done) { | ||
it('errors on missing segment', (done) => { | ||
var Obj = require('./import'); | ||
var client = new Catbox.Client(Obj); | ||
client.start(function (err) { | ||
const Obj = require('./import'); | ||
const client = new Catbox.Client(Obj); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
var key = { id: 'x' }; | ||
client.set(key, '123', 1000, function (err) { | ||
const key = { id: 'x' }; | ||
client.set(key, '123', 1000, (err) => { | ||
@@ -432,0 +434,0 @@ expect(err).to.exist(); |
@@ -0,4 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
const Hoek = require('hoek'); | ||
@@ -8,3 +10,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -65,3 +67,3 @@ | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
if (!segment) { | ||
@@ -71,3 +73,3 @@ return callback(null, null); | ||
var envelope = segment[key.id]; | ||
const envelope = segment[key.id]; | ||
if (!envelope) { | ||
@@ -77,3 +79,3 @@ return callback(null, null); | ||
var value = null; | ||
let value = null; | ||
try { | ||
@@ -86,3 +88,3 @@ value = JSON.parse(envelope.item); | ||
var result = { | ||
const result = { | ||
item: value, | ||
@@ -99,4 +101,2 @@ stored: envelope.stored, | ||
var self = this; | ||
callback = Hoek.nextTick(callback); | ||
@@ -108,3 +108,3 @@ | ||
var stringifiedValue = null; | ||
let stringifiedValue = null; | ||
try { | ||
@@ -117,3 +117,3 @@ stringifiedValue = JSON.stringify(value); | ||
var envelope = { | ||
const envelope = { | ||
item: stringifiedValue, | ||
@@ -125,5 +125,5 @@ stored: Date.now(), | ||
this.cache[key.segment] = this.cache[key.segment] || {}; | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
var cachedItem = segment[key.id]; | ||
const cachedItem = segment[key.id]; | ||
if (cachedItem && cachedItem.timeoutId) { | ||
@@ -133,5 +133,5 @@ clearTimeout(cachedItem.timeoutId); | ||
var timeoutId = setTimeout(function () { | ||
const timeoutId = setTimeout(() => { | ||
self.drop(key, function () { }); | ||
this.drop(key, () => { }); | ||
}, ttl); | ||
@@ -154,5 +154,4 @@ | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
if (segment) { | ||
var item = segment[key.id]; | ||
delete segment[key.id]; | ||
@@ -159,0 +158,0 @@ } |
@@ -0,7 +1,9 @@ | ||
'use strict'; | ||
// Load modules | ||
var Catbox = require('..'); | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var Import = require('./import'); | ||
const Catbox = require('..'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Import = require('./import'); | ||
@@ -11,3 +13,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -17,14 +19,14 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.experiment; | ||
var it = lab.test; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.experiment; | ||
const it = lab.test; | ||
const expect = Code.expect; | ||
describe('Catbox', function () { | ||
describe('Catbox', () => { | ||
it('creates a new connection', function (done) { | ||
it('creates a new connection', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
@@ -36,6 +38,6 @@ expect(client.isReady()).to.equal(true); | ||
it('closes the connection', function (done) { | ||
it('closes the connection', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
@@ -49,12 +51,12 @@ expect(client.isReady()).to.equal(true); | ||
it('gets an item after setting it', function (done) { | ||
it('gets an item after setting it', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 500, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 500, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -69,11 +71,11 @@ expect(err).to.equal(null); | ||
it('fails setting an item circular references', function (done) { | ||
it('fails setting an item circular references', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
var value = { a: 1 }; | ||
const key = { id: 'x', segment: 'test' }; | ||
const value = { a: 1 }; | ||
value.b = value; | ||
client.set(key, value, 10, function (err) { | ||
client.set(key, value, 10, (err) => { | ||
@@ -86,9 +88,9 @@ expect(err.message).to.equal('Converting circular structure to JSON'); | ||
it('ignored starting a connection twice on same event', function (done) { | ||
it('ignored starting a connection twice on same event', (done) => { | ||
var client = new Catbox.Client(Import); | ||
var x = 2; | ||
var start = function () { | ||
const client = new Catbox.Client(Import); | ||
let x = 2; | ||
const start = function () { | ||
client.start(function (err) { | ||
client.start((err) => { | ||
@@ -107,6 +109,6 @@ expect(client.isReady()).to.equal(true); | ||
it('ignored starting a connection twice chained', function (done) { | ||
it('ignored starting a connection twice chained', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
@@ -116,3 +118,3 @@ expect(err).to.not.exist(); | ||
client.start(function (err) { | ||
client.start((err) => { | ||
@@ -126,8 +128,8 @@ expect(err).to.not.exist(); | ||
it('returns not found on get when using null key', function (done) { | ||
it('returns not found on get when using null key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.get(null, function (err, result) { | ||
client.get(null, (err, result) => { | ||
@@ -141,14 +143,14 @@ expect(err).to.equal(null); | ||
it('returns not found on get when item expired', function (done) { | ||
it('returns not found on get when item expired', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'x', 1, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'x', 1, (err) => { | ||
expect(err).to.not.exist(); | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -164,8 +166,8 @@ expect(err).to.equal(null); | ||
it('returns error on set when using null key', function (done) { | ||
it('returns error on set when using null key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.set(null, {}, 1000, function (err) { | ||
client.set(null, {}, 1000, (err) => { | ||
@@ -178,8 +180,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('returns error on get when using invalid key', function (done) { | ||
it('returns error on get when using invalid key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.get({}, function (err) { | ||
client.get({}, (err) => { | ||
@@ -192,8 +194,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('returns error on drop when using invalid key', function (done) { | ||
it('returns error on drop when using invalid key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.drop({}, function (err) { | ||
client.drop({}, (err) => { | ||
@@ -206,8 +208,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('returns error on set when using invalid key', function (done) { | ||
it('returns error on set when using invalid key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.set({}, {}, 1000, function (err) { | ||
client.set({}, {}, 1000, (err) => { | ||
@@ -220,9 +222,9 @@ expect(err instanceof Error).to.equal(true); | ||
it('ignores set when using non-positive ttl value', function (done) { | ||
it('ignores set when using non-positive ttl value', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'y', 0, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'y', 0, (err) => { | ||
@@ -235,8 +237,8 @@ expect(err).to.not.exist(); | ||
it('returns error on drop when using null key', function (done) { | ||
it('returns error on drop when using null key', (done) => { | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Import); | ||
client.start((err) => { | ||
client.drop(null, function (err) { | ||
client.drop(null, (err) => { | ||
@@ -249,8 +251,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('returns error on get when stopped', function (done) { | ||
it('returns error on get when stopped', (done) => { | ||
var client = new Catbox.Client(Import); | ||
const client = new Catbox.Client(Import); | ||
client.stop(); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.connection.get(key, function (err, result) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.connection.get(key, (err, result) => { | ||
@@ -263,8 +265,8 @@ expect(err).to.exist(); | ||
it('returns error on set when stopped', function (done) { | ||
it('returns error on set when stopped', (done) => { | ||
var client = new Catbox.Client(Import); | ||
const client = new Catbox.Client(Import); | ||
client.stop(); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.connection.set(key, 'y', 1, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.connection.set(key, 'y', 1, (err) => { | ||
@@ -276,8 +278,8 @@ expect(err).to.exist(); | ||
it('returns error on drop when stopped', function (done) { | ||
it('returns error on drop when stopped', (done) => { | ||
var client = new Catbox.Client(Import); | ||
const client = new Catbox.Client(Import); | ||
client.stop(); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.connection.drop(key, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.connection.drop(key, (err) => { | ||
@@ -289,11 +291,11 @@ expect(err).to.exist(); | ||
it('returns error on missing segment name', function (done) { | ||
it('returns error on missing segment name', (done) => { | ||
var config = { | ||
const config = { | ||
expiresIn: 50000 | ||
}; | ||
var fn = function () { | ||
const fn = function () { | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy(config, client, ''); | ||
const client = new Catbox.Client(Import); | ||
new Catbox.Policy(config, client, ''); | ||
}; | ||
@@ -304,11 +306,11 @@ expect(fn).to.throw(Error); | ||
it('returns error on bad segment name', function (done) { | ||
it('returns error on bad segment name', (done) => { | ||
var config = { | ||
const config = { | ||
expiresIn: 50000 | ||
}; | ||
var fn = function () { | ||
const fn = function () { | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy(config, client, 'a\0b'); | ||
const client = new Catbox.Client(Import); | ||
new Catbox.Policy(config, client, 'a\0b'); | ||
}; | ||
@@ -319,7 +321,7 @@ expect(fn).to.throw(Error); | ||
it('returns error when cache item dropped while stopped', function (done) { | ||
it('returns error when cache item dropped while stopped', (done) => { | ||
var client = new Catbox.Client(Import); | ||
const client = new Catbox.Client(Import); | ||
client.stop(); | ||
client.drop('a', function (err) { | ||
client.drop('a', (err) => { | ||
@@ -326,0 +328,0 @@ expect(err).to.exist(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
153
171643
2661
+ Addedboom@3.2.2(transitive)
+ Addedhoek@3.0.44.3.1(transitive)
+ Addedisemail@2.2.1(transitive)
+ Addedjoi@7.3.0(transitive)
+ Addedtopo@2.1.1(transitive)
- Removedboom@2.10.1(transitive)
- Removedhoek@2.16.3(transitive)
- Removedisemail@1.2.0(transitive)
- Removedjoi@6.10.1(transitive)
- Removedtopo@1.1.0(transitive)
Updatedboom@3.x.x
Updatedhoek@3.x.x
Updatedjoi@7.x.x