Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

catbox-memory

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catbox-memory - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

lib/index.js

@@ -19,2 +19,3 @@ // Load modules

Hoek.assert(this.constructor === internals.Connection, 'Memory cache client must be instantiated using new');
Hoek.assert(!options || options.maxByteSize === undefined || options.maxByteSize >= 0, 'Invalid cache maxByteSize value');

@@ -131,5 +132,6 @@ this.settings = Hoek.applyToDefaults(internals.defaults, options || {});

var cachedItem = segment[key.id];
if (cachedItem && cachedItem.timeoutId) {
if (cachedItem &&
cachedItem.timeoutId) {
clearTimeout(cachedItem.timeoutId);
if (cachedItem.byteSize) {

@@ -140,5 +142,3 @@ self.byteSize -= cachedItem.byteSize; // If the item existed, decrement the byteSize as the value could be different

if (this.settings.maxByteSize &&
this.settings.maxByteSize > 0) {
if (this.settings.maxByteSize) {
envelope.byteSize = 53 + Buffer.byteLength(envelope.item) + Buffer.byteLength(key.segment) + Buffer.byteLength(key.id); // Envelope size without value: 53 bytes

@@ -145,0 +145,0 @@ if (self.byteSize + envelope.byteSize > this.settings.maxByteSize) {

{
"name": "catbox-memory",
"description": "Memory adapter for catbox",
"version": "1.0.1",
"version": "1.0.2",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -20,10 +20,7 @@ "contributors": [

"dependencies": {
"hoek": "1.x.x"
"hoek": "2.x.x"
},
"peerDependencies": {
"catbox": "2.x.x"
},
"devDependencies": {
"catbox": "2.x.x",
"lab": "1.x.x"
"lab": "3.x.x"
},

@@ -30,0 +27,0 @@ "scripts": {

@@ -57,3 +57,3 @@ // Load modules

it('gets an item after settig it', function (done) {
it('gets an item after setting it', function (done) {

@@ -77,2 +77,31 @@ var client = new Catbox.Client(Memory);

it('gets an item after setting it (no memory limit)', function (done) {
var client = new Catbox.Client(new Memory({ maxByteSize: 0 }));
client.start(function (err) {
var key = { id: 'x', segment: 'test' };
client.set(key, '123', 500, function (err) {
expect(err).to.not.exist;
client.get(key, function (err, result) {
expect(err).to.equal(null);
expect(result.item).to.equal('123');
client.set(key, '345', 500, function (err) {
expect(err).to.not.exist;
client.get(key, function (err, result) {
expect(err).to.equal(null);
expect(result.item).to.equal('345');
done();
});
});
});
});
});
});
it('fails setting an item circular references', function (done) {

@@ -181,3 +210,3 @@

it('returns error on set when using null key', function (done) {
it('errors on set when using null key', function (done) {

@@ -195,3 +224,3 @@ var client = new Catbox.Client(Memory);

it('returns error on get when using invalid key', function (done) {
it('errors on get when using invalid key', function (done) {

@@ -209,3 +238,3 @@ var client = new Catbox.Client(Memory);

it('returns error on drop when using invalid key', function (done) {
it('errors on set when using invalid key', function (done) {

@@ -215,15 +244,2 @@ var client = new Catbox.Client(Memory);

client.drop({}, function (err) {
expect(err instanceof Error).to.equal(true);
done();
});
});
});
it('returns error on set when using invalid key', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
client.set({}, {}, 1000, function (err) {

@@ -251,18 +267,5 @@

it('returns error on drop when using null key', function (done) {
it('errors on get when stopped', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
client.drop(null, function (err) {
expect(err instanceof Error).to.equal(true);
done();
});
});
});
it('returns error on get when stopped', function (done) {
var client = new Catbox.Client(Memory);
client.stop();

@@ -278,3 +281,3 @@ var key = { id: 'x', segment: 'test' };

it('returns error on set when stopped', function (done) {
it('errors on set when stopped', function (done) {

@@ -291,16 +294,4 @@ var client = new Catbox.Client(Memory);

it('returns error on drop when stopped', function (done) {
it('errors on missing segment name', function (done) {
var client = new Catbox.Client(Memory);
client.stop();
var key = { id: 'x', segment: 'test' };
client.connection.drop(key, function (err) {
expect(err).to.exist;
done();
});
});
it('returns error on missing segment name', function (done) {
var config = {

@@ -318,3 +309,3 @@ expiresIn: 50000

it('returns error on bad segment name', function (done) {
it('errors on bad segment name', function (done) {

@@ -333,13 +324,2 @@ var config = {

it('returns error when cache item dropped while stopped', function (done) {
var client = new Catbox.Client(Memory);
client.stop();
client.drop('a', function (err) {
expect(err).to.exist;
done();
});
});
describe('#start', function () {

@@ -377,3 +357,3 @@

it('returns error on invalid json in cache', function (done) {
it('errors on invalid json in cache', function (done) {

@@ -475,3 +455,3 @@ var key = {

it('returns an error when the maxByteSize has been reached', function (done) {
it('errors when the maxByteSize has been reached', function (done) {

@@ -498,3 +478,3 @@ var key = {

it('increments the byte size when an item is inserted and returns an error when the limit is reached', function (done) {
it('increments the byte size when an item is inserted and errors when the limit is reached', function (done) {

@@ -595,5 +575,117 @@ var key1 = {

describe('#drop', function () {
it('drops an existing item', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
var key = { id: 'x', segment: 'test' };
client.set(key, '123', 500, function (err) {
expect(err).to.not.exist;
client.get(key, function (err, result) {
expect(err).to.equal(null);
expect(result.item).to.equal('123');
client.drop(key, function (err) {
expect(err).to.not.exist;
done();
});
});
});
});
});
it('drops an item from a missing segment', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
var key = { id: 'x', segment: 'test' };
client.drop(key, function (err) {
expect(err).to.not.exist;
done();
});
});
});
it('drops a missing item', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
var key = { id: 'x', segment: 'test' };
client.set(key, '123', 500, function (err) {
expect(err).to.not.exist;
client.get(key, function (err, result) {
expect(err).to.equal(null);
expect(result.item).to.equal('123');
client.drop({ id: 'y', segment: 'test' }, function (err) {
expect(err).to.not.exist;
done();
});
});
});
});
});
it('errors on drop when using invalid key', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
client.drop({}, function (err) {
expect(err instanceof Error).to.equal(true);
done();
});
});
});
it('errors on drop when using null key', function (done) {
var client = new Catbox.Client(Memory);
client.start(function (err) {
client.drop(null, function (err) {
expect(err instanceof Error).to.equal(true);
done();
});
});
});
it('errors on drop when stopped', function (done) {
var client = new Catbox.Client(Memory);
client.stop();
var key = { id: 'x', segment: 'test' };
client.connection.drop(key, function (err) {
expect(err).to.exist;
done();
});
});
it('errors when cache item dropped while stopped', function (done) {
var client = new Catbox.Client(Memory);
client.stop();
client.drop('a', function (err) {
expect(err).to.exist;
done();
});
});
});
describe('#validateSegmentName', function () {
it('returns an error when the name is empty', function (done) {
it('errors when the name is empty', function (done) {

@@ -608,3 +700,3 @@ var memory = new Memory();

it('returns an error when the name has a null character', function (done) {
it('errors when the name has a null character', function (done) {

@@ -611,0 +703,0 @@ var memory = new Memory();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc