catbox-memory
Advanced tools
Comparing version 1.1.2 to 2.0.0
@@ -0,4 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hoek = require('hoek'); | ||
const Hoek = require('hoek'); | ||
@@ -8,3 +10,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -23,3 +25,3 @@ | ||
var valueByteSize = 0; | ||
let valueByteSize = 0; | ||
@@ -76,8 +78,8 @@ if (allowMixedContent && Buffer.isBuffer(value)) { | ||
if (this.cache) { | ||
var segments = Object.keys(this.cache); | ||
for (var i = 0, il = segments.length; i < il; ++i) { | ||
var segment = segments[i]; | ||
var keys = Object.keys(this.cache[segment]); | ||
for (var j = 0, jl = keys.length; j < jl; ++j) { | ||
var key = keys[j]; | ||
const segments = Object.keys(this.cache); | ||
for (let i = 0; i < segments.length; ++i) { | ||
const segment = segments[i]; | ||
const keys = Object.keys(this.cache[segment]); | ||
for (let j = 0; j < keys.length; ++j) { | ||
const key = keys[j]; | ||
clearTimeout(this.cache[segment][key].timeoutId); | ||
@@ -96,3 +98,3 @@ } | ||
return (!!this.cache); | ||
return !!this.cache; | ||
}; | ||
@@ -123,3 +125,4 @@ | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
if (!segment) { | ||
@@ -129,3 +132,4 @@ return callback(null, null); | ||
var envelope = segment[key.id]; | ||
const envelope = segment[key.id]; | ||
if (!envelope) { | ||
@@ -135,3 +139,3 @@ return callback(null, null); | ||
var value = null; | ||
let value = null; | ||
@@ -149,3 +153,3 @@ if (Buffer.isBuffer(envelope.item)) { | ||
var result = { | ||
const result = { | ||
item: value, | ||
@@ -162,4 +166,2 @@ stored: envelope.stored, | ||
var self = this; | ||
callback = Hoek.nextTick(callback); | ||
@@ -175,6 +177,7 @@ | ||
var envelope = null; | ||
let envelope = null; | ||
try { | ||
envelope = new internals.MemoryCacheEntry(key, value, ttl, this.settings.allowMixedContent); | ||
} catch (err) { | ||
} | ||
catch (err) { | ||
return callback(err); | ||
@@ -184,14 +187,12 @@ } | ||
this.cache[key.segment] = this.cache[key.segment] || new internals.MemoryCacheSegment(); | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
const cachedItem = segment[key.id]; | ||
var cachedItem = segment[key.id]; | ||
if (cachedItem && | ||
cachedItem.timeoutId) { | ||
if (cachedItem && cachedItem.timeoutId) { | ||
clearTimeout(cachedItem.timeoutId); | ||
self.byteSize -= cachedItem.byteSize; // If the item existed, decrement the byteSize as the value could be different | ||
this.byteSize -= cachedItem.byteSize; // If the item existed, decrement the byteSize as the value could be different | ||
} | ||
if (this.settings.maxByteSize) { | ||
if (self.byteSize + envelope.byteSize > this.settings.maxByteSize) { | ||
if (this.byteSize + envelope.byteSize > this.settings.maxByteSize) { | ||
return callback(new Error('Cache size limit reached')); | ||
@@ -201,5 +202,5 @@ } | ||
var timeoutId = setTimeout(function () { | ||
const timeoutId = setTimeout(() => { | ||
self.drop(key, function () { }); | ||
this.drop(key, () => {}); | ||
}, ttl); | ||
@@ -224,5 +225,5 @@ | ||
var segment = this.cache[key.segment]; | ||
const segment = this.cache[key.segment]; | ||
if (segment) { | ||
var item = segment[key.id]; | ||
const item = segment[key.id]; | ||
@@ -242,3 +243,3 @@ if (item) { | ||
var obj = null; | ||
let obj = null; | ||
@@ -245,0 +246,0 @@ try { |
{ | ||
"name": "catbox-memory", | ||
"description": "Memory adapter for catbox", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"repository": "git://github.com/hapijs/catbox-memory", | ||
@@ -13,11 +13,11 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.30" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"hoek": "2.x.x" | ||
"hoek": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"catbox": "6.x.x", | ||
"lab": "5.x.x", | ||
"code": "1.x.x" | ||
"lab": "7.x.x", | ||
"code": "2.x.x" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
@@ -0,7 +1,9 @@ | ||
'use strict'; | ||
// Load modules | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var Catbox = require('catbox'); | ||
var Memory = require('..'); | ||
const Code = require('code'); | ||
const Lab = require('lab'); | ||
const Catbox = require('catbox'); | ||
const Memory = require('..'); | ||
@@ -11,3 +13,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -17,13 +19,13 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('Memory', function () { | ||
describe('Memory', () => { | ||
it('throws an error if not created with new', function (done) { | ||
it('throws an error if not created with new', (done) => { | ||
var fn = function () { | ||
const fn = () => { | ||
@@ -37,7 +39,8 @@ Memory(); | ||
it('creates a new connection', function (done) { | ||
it('creates a new connection', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
expect(client.isReady()).to.equal(true); | ||
@@ -48,7 +51,8 @@ done(); | ||
it('closes the connection', function (done) { | ||
it('closes the connection', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
expect(client.isReady()).to.equal(true); | ||
@@ -61,12 +65,13 @@ client.stop(); | ||
it('gets an item after setting it', function (done) { | ||
it('gets an item after setting it', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 500, function (err) { | ||
client.start((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) => { | ||
@@ -81,15 +86,15 @@ expect(err).to.equal(null); | ||
it('buffers can be set and retrieved when allowMixedContent is true', function (done) { | ||
it('buffers can be set and retrieved when allowMixedContent is true', (done) => { | ||
var buffer = new Buffer('string value'); | ||
var client = new Catbox.Client(new Memory({ allowMixedContent: true })); | ||
const buffer = new Buffer('string value'); | ||
const client = new Catbox.Client(new Memory({ allowMixedContent: true })); | ||
client.start(function (err) { | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, buffer, 500, function (err) { | ||
client.set(key, buffer, 500, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -105,15 +110,15 @@ expect(err).to.not.exist(); | ||
it('buffers are copied before storing when allowMixedContent is true', function (done) { | ||
it('buffers are copied before storing when allowMixedContent is true', (done) => { | ||
var buffer = new Buffer('string value'); | ||
var client = new Catbox.Client(new Memory({ allowMixedContent: true })); | ||
const buffer = new Buffer('string value'); | ||
const client = new Catbox.Client(new Memory({ allowMixedContent: true })); | ||
client.start(function (err) { | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, buffer, 500, function (err) { | ||
client.set(key, buffer, 500, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -128,15 +133,15 @@ expect(err).to.not.exist(); | ||
it('buffers are stringified when allowMixedContent is not true', function (done) { | ||
it('buffers are stringified when allowMixedContent is not true', (done) => { | ||
var buffer = new Buffer('string value'); | ||
var client = new Catbox.Client(new Memory()); | ||
const buffer = new Buffer('string value'); | ||
const client = new Catbox.Client(new Memory()); | ||
client.start(function (err) { | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, buffer, 500, function (err) { | ||
client.set(key, buffer, 500, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, result) { | ||
client.get(key, (err, result) => { | ||
@@ -152,12 +157,14 @@ expect(err).to.not.exist(); | ||
it('gets an item after setting it (no memory limit)', function (done) { | ||
it('gets an item after setting it (no memory limit)', (done) => { | ||
var client = new Catbox.Client(new Memory({ maxByteSize: 0 })); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(new Memory({ maxByteSize: 0 })); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 500, function (err) { | ||
client.start((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) => { | ||
@@ -167,6 +174,6 @@ expect(err).to.equal(null); | ||
client.set(key, '345', 500, function (err) { | ||
client.set(key, '345', 500, (err) => { | ||
expect(err).to.not.exist(); | ||
client.get(key, function (err, data) { | ||
client.get(key, (err, data) => { | ||
@@ -183,11 +190,13 @@ 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(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
var key = { id: 'x', segment: 'test' }; | ||
var value = { a: 1 }; | ||
client.start((err) => { | ||
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) => { | ||
@@ -200,10 +209,12 @@ expect(err.message).to.equal('Converting circular structure to JSON'); | ||
it('fails setting an item with very long ttl', function (done) { | ||
it('fails setting an item with very long ttl', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', Math.pow(2, 31), function (err) { | ||
client.start((err) => { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', Math.pow(2, 31), (err) => { | ||
expect(err.message).to.equal('Invalid ttl (greater than 2147483647)'); | ||
@@ -215,9 +226,9 @@ done(); | ||
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(Memory); | ||
var x = 2; | ||
var start = function () { | ||
const client = new Catbox.Client(Memory); | ||
let x = 2; | ||
const start = () => { | ||
client.start(function (err) { | ||
client.start((err) => { | ||
@@ -236,11 +247,12 @@ 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(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
expect(err).to.not.exist(); | ||
expect(client.isReady()).to.equal(true); | ||
client.start(function (err) { | ||
client.start((err) => { | ||
@@ -254,9 +266,10 @@ 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(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.get(null, function (err, result) { | ||
client.start((err) => { | ||
client.get(null, (err, result) => { | ||
expect(err).to.equal(null); | ||
@@ -269,14 +282,16 @@ expect(result).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(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'x', 1, function (err) { | ||
client.start((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) => { | ||
@@ -292,9 +307,10 @@ expect(err).to.equal(null); | ||
it('errors on set when using null key', function (done) { | ||
it('errors on set when using null key', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.set(null, {}, 1000, function (err) { | ||
client.start((err) => { | ||
client.set(null, {}, 1000, (err) => { | ||
expect(err instanceof Error).to.equal(true); | ||
@@ -306,9 +322,10 @@ done(); | ||
it('errors on get when using invalid key', function (done) { | ||
it('errors on get when using invalid key', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.get({}, function (err) { | ||
client.start((err) => { | ||
client.get({}, (err) => { | ||
expect(err instanceof Error).to.equal(true); | ||
@@ -320,9 +337,10 @@ done(); | ||
it('errors on set when using invalid key', function (done) { | ||
it('errors on set when using invalid key', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.set({}, {}, 1000, function (err) { | ||
client.start((err) => { | ||
client.set({}, {}, 1000, (err) => { | ||
expect(err instanceof Error).to.equal(true); | ||
@@ -334,10 +352,12 @@ done(); | ||
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(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'y', 0, function (err) { | ||
client.start((err) => { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.set(key, 'y', 0, (err) => { | ||
expect(err).to.not.exist(); | ||
@@ -349,9 +369,10 @@ done(); | ||
it('errors on get when stopped', function (done) { | ||
it('errors on get when stopped', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
expect(err).to.exist(); | ||
@@ -363,8 +384,8 @@ expect(result).to.not.exist(); | ||
it('errors on set when stopped', function (done) { | ||
it('errors on set when stopped', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
@@ -376,11 +397,11 @@ expect(err).to.exist(); | ||
it('errors on missing segment name', function (done) { | ||
it('errors on missing segment name', (done) => { | ||
var config = { | ||
const config = { | ||
expiresIn: 50000 | ||
}; | ||
var fn = function () { | ||
const fn = () => { | ||
var client = new Catbox.Client(Memory); | ||
var cache = new Catbox.Policy(config, client, ''); | ||
const client = new Catbox.Client(Memory); | ||
const cache = new Catbox.Policy(config, client, ''); // eslint-disable-line no-unused-vars | ||
}; | ||
@@ -391,11 +412,11 @@ expect(fn).to.throw(Error); | ||
it('errors on bad segment name', function (done) { | ||
it('errors on bad segment name', (done) => { | ||
var config = { | ||
const config = { | ||
expiresIn: 50000 | ||
}; | ||
var fn = function () { | ||
const fn = () => { | ||
var client = new Catbox.Client(Memory); | ||
var cache = new Catbox.Policy(config, client, 'a\u0000b'); | ||
const client = new Catbox.Client(Memory); | ||
const cache = new Catbox.Policy(config, client, 'a\u0000b'); // eslint-disable-line no-unused-vars | ||
}; | ||
@@ -406,8 +427,8 @@ expect(fn).to.throw(Error); | ||
it('cleans up timers when stopped', { parallel: false }, function (done) { | ||
it('cleans up timers when stopped', { parallel: false }, (done) => { | ||
var cleared; | ||
var set; | ||
let cleared; | ||
let set; | ||
var oldClear = clearTimeout; | ||
const oldClear = clearTimeout; | ||
clearTimeout = function (id) { | ||
@@ -419,3 +440,3 @@ | ||
var oldSet = setTimeout; | ||
const oldSet = setTimeout; | ||
setTimeout = function (fn, time) { | ||
@@ -427,7 +448,7 @@ | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
@@ -445,9 +466,9 @@ client.stop(); | ||
describe('start()', function () { | ||
describe('start()', () => { | ||
it('creates an empty cache object', function (done) { | ||
it('creates an empty cache object', (done) => { | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
@@ -460,9 +481,9 @@ expect(memory.cache).to.exist(); | ||
describe('stop()', function () { | ||
describe('stop()', () => { | ||
it('sets the cache object to null', function (done) { | ||
it('sets the cache object to null', (done) => { | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
@@ -477,7 +498,7 @@ expect(memory.cache).to.exist(); | ||
describe('get()', function () { | ||
describe('get()', () => { | ||
it('errors on invalid json in cache', function (done) { | ||
it('errors on invalid json in cache', (done) => { | ||
var key = { | ||
const key = { | ||
segment: 'test', | ||
@@ -487,13 +508,13 @@ id: 'test' | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key, 'myvalue', 10, function () { | ||
memory.set(key, 'myvalue', 10, () => { | ||
expect(memory.cache[key.segment][key.id].item).to.equal('"myvalue"'); | ||
memory.cache[key.segment][key.id].item = '"myvalue'; | ||
memory.get(key, function (err, result) { | ||
memory.get(key, (err, result) => { | ||
@@ -507,5 +528,5 @@ expect(err.message).to.equal('Bad value content'); | ||
it('returns not found on missing segment', function (done) { | ||
it('returns not found on missing segment', (done) => { | ||
var key = { | ||
const key = { | ||
segment: 'test', | ||
@@ -515,9 +536,9 @@ id: 'test' | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.get(key, function (err, result) { | ||
memory.get(key, (err, result) => { | ||
@@ -532,7 +553,7 @@ expect(err).to.not.exist(); | ||
describe('set()', function () { | ||
describe('set()', () => { | ||
it('adds an item to the cache object', function (done) { | ||
it('adds an item to the cache object', (done) => { | ||
var key = { | ||
const key = { | ||
segment: 'test', | ||
@@ -542,9 +563,9 @@ id: 'test' | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key, 'myvalue', 10, function () { | ||
memory.set(key, 'myvalue', 10, () => { | ||
@@ -557,5 +578,5 @@ expect(memory.cache[key.segment][key.id].item).to.equal('"myvalue"'); | ||
it('removes an item from the cache object when it expires', function (done) { | ||
it('removes an item from the cache object when it expires', (done) => { | ||
var key = { | ||
const key = { | ||
segment: 'test', | ||
@@ -565,12 +586,12 @@ id: 'test' | ||
var memory = new Memory(); | ||
const memory = new Memory(); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key, 'myvalue', 10, function () { | ||
memory.set(key, 'myvalue', 10, () => { | ||
expect(memory.cache[key.segment][key.id].item).to.equal('"myvalue"'); | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
@@ -584,5 +605,5 @@ expect(memory.cache[key.segment][key.id]).to.not.exist(); | ||
it('errors when the maxByteSize has been reached', function (done) { | ||
it('errors when the maxByteSize has been reached', (done) => { | ||
var key = { | ||
const key = { | ||
segment: 'test', | ||
@@ -592,9 +613,9 @@ id: 'test' | ||
var memory = new Memory({ maxByteSize: 4 }); | ||
const memory = new Memory({ maxByteSize: 4 }); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key, 'myvalue', 10, function (err) { | ||
memory.set(key, 'myvalue', 10, (err) => { | ||
@@ -608,5 +629,5 @@ expect(err).to.exist(); | ||
it('increments the byte size when an item is inserted and errors when the limit is reached', function (done) { | ||
it('increments the byte size when an item is inserted and errors when the limit is reached', (done) => { | ||
var key1 = { | ||
const key1 = { | ||
segment: 'test', | ||
@@ -616,3 +637,3 @@ id: 'test' | ||
var key2 = { | ||
const key2 = { | ||
segment: 'test', | ||
@@ -624,9 +645,9 @@ id: 'test2' | ||
// amount of free space, but not enough for the second key to be created. | ||
var memory = new Memory({ maxByteSize: 200 }); | ||
const memory = new Memory({ maxByteSize: 200 }); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key1, 'my', 10, function (err) { | ||
memory.set(key1, 'my', 10, (err) => { | ||
@@ -636,3 +657,3 @@ expect(err).to.not.exist(); | ||
memory.set(key2, 'myvalue', 10, function (err) { | ||
memory.set(key2, 'myvalue', 10, (err) => { | ||
@@ -646,9 +667,9 @@ expect(err).to.exist(); | ||
it('increments the byte size when an object is inserted', function (done) { | ||
it('increments the byte size when an object is inserted', (done) => { | ||
var key1 = { | ||
const key1 = { | ||
segment: 'test', | ||
id: 'test' | ||
}; | ||
var itemToStore = { | ||
const itemToStore = { | ||
my: { | ||
@@ -661,9 +682,9 @@ array: [1, 2, 3], | ||
var memory = new Memory({ maxByteSize: 2000 }); | ||
const memory = new Memory({ maxByteSize: 2000 }); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key1, itemToStore, 10, function () { | ||
memory.set(key1, itemToStore, 10, () => { | ||
@@ -678,9 +699,9 @@ expect(memory.byteSize).to.equal(204); | ||
it('leaves the byte size unchanged when an object overrides existing key with same size', function (done) { | ||
it('leaves the byte size unchanged when an object overrides existing key with same size', (done) => { | ||
var key1 = { | ||
const key1 = { | ||
segment: 'test', | ||
id: 'test' | ||
}; | ||
var itemToStore = { | ||
const itemToStore = { | ||
my: { | ||
@@ -694,13 +715,13 @@ array: [1, 2, 3], | ||
var memory = new Memory({ maxByteSize: 2000 }); | ||
const memory = new Memory({ maxByteSize: 2000 }); | ||
expect(memory.cache).to.not.exist(); | ||
memory.start(function () { | ||
memory.start(() => { | ||
expect(memory.cache).to.exist(); | ||
memory.set(key1, itemToStore, 10, function () { | ||
memory.set(key1, itemToStore, 10, () => { | ||
expect(memory.cache[key1.segment][key1.id].byteSize).to.equal(204); | ||
expect(memory.cache[key1.segment][key1.id].item).to.exist(); | ||
memory.set(key1, itemToStore, 10, function () { | ||
memory.set(key1, itemToStore, 10, () => { | ||
@@ -716,18 +737,18 @@ expect(memory.cache[key1.segment][key1.id].byteSize).to.equal(204); | ||
describe('drop()', function () { | ||
describe('drop()', () => { | ||
it('drops an existing item', function (done) { | ||
it('drops an existing item', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
expect(err).to.equal(null); | ||
expect(result.item).to.equal('123'); | ||
client.drop(key, function (err) { | ||
client.drop(key, (err) => { | ||
@@ -742,9 +763,9 @@ expect(err).to.not.exist(); | ||
it('drops an item from a missing segment', function (done) { | ||
it('drops an item from a missing segment', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
var key = { id: 'x', segment: 'test' }; | ||
client.drop(key, function (err) { | ||
const key = { id: 'x', segment: 'test' }; | ||
client.drop(key, (err) => { | ||
@@ -757,16 +778,16 @@ expect(err).to.not.exist(); | ||
it('drops a missing item', function (done) { | ||
it('drops a missing item', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
expect(err).to.equal(null); | ||
expect(result.item).to.equal('123'); | ||
client.drop({ id: 'y', segment: 'test' }, function (err) { | ||
client.drop({ id: 'y', segment: 'test' }, (err) => { | ||
@@ -781,8 +802,8 @@ expect(err).to.not.exist(); | ||
it('errors on drop when using invalid key', function (done) { | ||
it('errors on drop when using invalid key', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
client.drop({}, function (err) { | ||
client.drop({}, (err) => { | ||
@@ -795,8 +816,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('errors on drop when using null key', function (done) { | ||
it('errors on drop when using null key', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
client.start(function (err) { | ||
const client = new Catbox.Client(Memory); | ||
client.start((err) => { | ||
client.drop(null, function (err) { | ||
client.drop(null, (err) => { | ||
@@ -809,8 +830,8 @@ expect(err instanceof Error).to.equal(true); | ||
it('errors on drop when stopped', function (done) { | ||
it('errors on drop when stopped', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
const client = new Catbox.Client(Memory); | ||
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) => { | ||
@@ -822,7 +843,7 @@ expect(err).to.exist(); | ||
it('errors when cache item dropped while stopped', function (done) { | ||
it('errors when cache item dropped while stopped', (done) => { | ||
var client = new Catbox.Client(Memory); | ||
const client = new Catbox.Client(Memory); | ||
client.stop(); | ||
client.drop('a', function (err) { | ||
client.drop('a', (err) => { | ||
@@ -835,8 +856,8 @@ expect(err).to.exist(); | ||
describe('validateSegmentName()', function () { | ||
describe('validateSegmentName()', () => { | ||
it('errors when the name is empty', function (done) { | ||
it('errors when the name is empty', (done) => { | ||
var memory = new Memory(); | ||
var result = memory.validateSegmentName(''); | ||
const memory = new Memory(); | ||
const result = memory.validateSegmentName(''); | ||
@@ -848,6 +869,6 @@ expect(result).to.be.instanceOf(Error); | ||
it('errors when the name has a null character', function (done) { | ||
it('errors when the name has a null character', (done) => { | ||
var memory = new Memory(); | ||
var result = memory.validateSegmentName('\u0000test'); | ||
const memory = new Memory(); | ||
const result = memory.validateSegmentName('\u0000test'); | ||
@@ -858,6 +879,6 @@ expect(result).to.be.instanceOf(Error); | ||
it('returns null when there are no errors', function (done) { | ||
it('returns null when there are no errors', (done) => { | ||
var memory = new Memory(); | ||
var result = memory.validateSegmentName('valid'); | ||
const memory = new Memory(); | ||
const result = memory.validateSegmentName('valid'); | ||
@@ -864,0 +885,0 @@ expect(result).to.not.be.instanceOf(Error); |
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
755
31822
+ Addedhoek@3.0.4(transitive)
- Removedhoek@2.16.3(transitive)
Updatedhoek@3.x.x