Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

buffering-cache

Package Overview
Dependencies
53
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.1.2

15

index.js

@@ -54,2 +54,6 @@ const BufferCache = require('./lib');

if (!config.localCacheSize && config.localTtlMsec){
throw new Error('if localTtlMsec is provided, localCacheSize must be provided as well');
}
if (config.keyPrefix && (typeof config.keyPrefix !== 'string')) {

@@ -68,8 +72,15 @@ throw new Error('if provided, keyPrefix must be a string');

if (config.localCacheSize > 0) {
let ttl = DEFAULT_LOCAL_CACHE_TTL_MSEC;
if (config.localTtlMsec){
ttl = config.localTtlMsec;
} else if ( remoteCacheSpec.bufferTtl && remoteCacheSpec.bufferTtl < DEFAULT_LOCAL_CACHE_TTL_MSEC){
ttl = remoteCacheSpec.bufferTtl;
}
localCacheSpec = {
store: new MemoryCache(config.localCacheSize),
ttl: config.localTtlMsec || remoteCacheSpec.bufferTtl < DEFAULT_LOCAL_CACHE_TTL_MSEC ? remoteCacheSpec.bufferTtl : DEFAULT_LOCAL_CACHE_TTL_MSEC
ttl: ttl
};
}
return new BufferCache(remoteCacheSpec, localCacheSpec);

@@ -76,0 +87,0 @@ };

@@ -20,2 +20,3 @@ const Promise = require('bluebird');

// Add a parameter getter after lunch
self.client = params.store.client;

@@ -30,2 +31,5 @@

}
self.getParams = () => {
return params;
};

@@ -32,0 +36,0 @@ self.get = (key) => {

4

package.json
{
"name": "buffering-cache",
"version": "1.1.1",
"version": "1.1.2",
"description": "Node cache wrapper that keeps your cache warm",

@@ -34,3 +34,3 @@ "main": "index.js",

"chai-as-promised": "^6.0.0",
"codacy-coverage": "^2.0.0",
"codacy-coverage": "^2.0.2",
"eslint-plugin-no-only-tests": "^1.1.0",

@@ -37,0 +37,0 @@ "gb-license-check": "^1.0.1",

@@ -10,2 +10,3 @@ const chai = require('chai');

const MemoryCache = require('../lib/caches/memory');
const Cache = require('../index');

@@ -263,2 +264,290 @@ describe('buffering cache', () => {

});
it('configuration is not provided', () => {
expect(() => new Cache()).to.throw('configuration must be provided');
});
it('host is not present', () => {
const noHostConfig = {};
expect(() => new Cache(noHostConfig)).to.throw('host must be provided');
});
it('host is not valid', () => {
const wrongHostConfig = {host: 5};
expect(() => new Cache(wrongHostConfig)).to.throw('host must be provided');
});
it('port is not present', () => {
const sampleConfig = {
host: 'localhost'
};
expect(() => new Cache(sampleConfig)).to.throw('port must be a number 0-65535');
});
it('port is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 'strings lol'
};
expect(() => new Cache(sampleConfig)).to.throw('port must be a number 0-65535');
});
it('port is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 65536
};
expect(() => new Cache(sampleConfig)).to.throw('port must be a number 0-65535');
});
it('port is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: -1
};
expect(() => new Cache(sampleConfig)).to.throw('port must be a number 0-65535');
});
it('ttlMsec not provided', () => {
const sampleConfig = {
host: 'localhost',
port: 1337
};
expect(() => new Cache(sampleConfig)).to.throw('ttlMsec must be a number greater than 0');
});
it('ttlMsec not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 'moar strings'
};
expect(() => new Cache(sampleConfig)).to.throw('ttlMsec must be a number greater than 0');
});
it('ttlMsec out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: -1
};
expect(() => new Cache(sampleConfig)).to.throw('ttlMsec must be a number greater than 0');
});
it('db is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 'strings boogaloo'
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, db must be a number 0-255');
});
it('db is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: -1
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, db must be a number 0-255');
});
it('db is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 256
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, db must be a number 0-255');
});
it('bufferTtlMsec is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 'stringssss'
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, bufferTtlMsec must be a number greater than 0 and less than ttlMsec');
});
it('bufferTtlMsec is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: -1
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, bufferTtlMsec must be a number greater than 0 and less than ttlMsec');
});
it('bufferTtlMsec is greater than ttlMsec', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 200
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, bufferTtlMsec must be a number greater than 0 and less than ttlMsec');
});
it('localCacheSize is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 5,
localCacheSize: 'strings? strings?!! striiiiiings!!!'
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, localCacheSize must be a number gte 0');
});
it('localCacheSize is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 5,
localCacheSize: -1
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, localCacheSize must be a number gte 0');
});
it('localTtlMsec is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 5,
localCacheSize: 20,
localTtlMsec: '!(!string))'
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, localTtlMsec must be a number greater than 0 and less than bufferTtlMsec');
});
it('localTtlMsec is out of range', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 5,
localCacheSize: 20,
localTtlMsec: -1
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, localTtlMsec must be a number greater than 0 and less than bufferTtlMsec');
});
it('localTtlMsec is greater than bufferTtlMsec', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 5,
localCacheSize: 20,
localTtlMsec: 10
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, localTtlMsec must be a number greater than 0 and less than bufferTtlMsec');
});
it('localTtlMsec is provided but localCacheSize is not', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 10,
db: 255,
bufferTtlMsec: 10,
localTtlMsec: 5
};
expect(() => new Cache(sampleConfig)).to.throw('if localTtlMsec is provided, localCacheSize must be provided as well');
});
it('keyPrefix is not valid', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 600,
db: 255,
bufferTtlMsec: 500,
localCacheSize: 20,
localTtlMsec: 200,
keyPrefix: 2
};
expect(() => new Cache(sampleConfig)).to.throw('if provided, keyPrefix must be a string');
});
it('localCacheSize is not defined', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 600,
db: 255,
bufferTtlMsec: 400,
keyPrefix: 'prefix'
};
const sampleCache = new Cache(sampleConfig);
const parameters = sampleCache.localCache.getParams();
expect(parameters.ttl).to.eql(400);
});
it('localCacheSize is defined but localTtlMsec is not', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 600,
db: 255,
bufferTtlMsec: 600,
localCacheSize: 20,
keyPrefix: 'prefix'
};
const sampleCache = new Cache(sampleConfig);
const parameters = sampleCache.localCache.getParams();
expect(parameters.ttl).to.eql(500);
});
it('localCacheSize and localTtlMsec are defined', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 600,
db: 255,
bufferTtlMsec: 600,
localCacheSize: 20,
localTtlMsec: 300,
keyPrefix: 'prefix'
};
const sampleCache = new Cache(sampleConfig);
const parameters = sampleCache.localCache.getParams();
expect(parameters.ttl).to.eql(300);
});
it('ttl is assigned the value of remoteCacheSpec.bufferttl', () => {
const sampleConfig = {
host: 'localhost',
port: 1337,
ttlMsec: 600,
db: 255,
bufferTtlMsec: 450,
localCacheSize: 20,
keyPrefix: 'prefix'
};
const sampleCache = new Cache(sampleConfig);
const parameters = sampleCache.localCache.getParams();
expect(parameters.ttl).to.eql(450);
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc