Socket
Socket
Sign inDemoInstall

cache-manager

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

19

.jscs.json

@@ -27,2 +27,3 @@ {

"requireSpaceBeforeBlockStatements": true,
"disallowNewlineBeforeBlockStatements": true,

@@ -35,2 +36,14 @@ "requireSpacesInConditionalExpression": true,

"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpaceBeforeBinaryOperators": [

@@ -67,2 +80,8 @@ "+",

"maximumLineLength": {
"value": 120,
"allowUrlComments": true,
"allowRegex": true
},
"validateIndentation": 4,

@@ -69,0 +88,0 @@ "validateParameterSeparator": ", ",

40

examples/example.js

@@ -11,9 +11,9 @@ /*jshint unused:false*/

//
memory_cache.set('foo', 'bar', ttl, function (err) {
memory_cache.set('foo', 'bar', ttl, function(err) {
if (err) { throw err; }
memory_cache.get('foo', function (err, result) {
memory_cache.get('foo', function(err, result) {
console.log(result);
// >> 'bar'
memory_cache.del('foo', function (err) {
memory_cache.del('foo', function(err) {
if (err) {

@@ -27,3 +27,3 @@ console.log(err);

function get_user(id, cb) {
setTimeout(function () {
setTimeout(function() {
console.log("Fetching user from slow database.");

@@ -43,3 +43,3 @@ cb(null, {id: id, name: 'Bob'});

function get_cached_user_manually(id, cb) {
memory_cache.get(id, function (err, result) {
memory_cache.get(id, function(err, result) {
if (err) { return cb(err); }

@@ -51,3 +51,3 @@

get_user(id, function (err, result) {
get_user(id, function(err, result) {
if (err) { return cb(err); }

@@ -62,3 +62,3 @@ memory_cache.set(id, result);

function get_cached_user(id, cb) {
memory_cache.wrap(id, function (cache_callback) {
memory_cache.wrap(id, function(cache_callback) {
get_user(id, cache_callback);

@@ -68,7 +68,7 @@ }, cb);

get_cached_user(user_id, function (err, user) {
get_cached_user(user_id, function(err, user) {
// First time fetches the user from the (fake) database:
console.log(user);
get_cached_user(user_id, function (err, user) {
get_cached_user(user_id, function(err, user) {
// Second time fetches from cache.

@@ -85,11 +85,11 @@ console.log(user);

// Same as above, but written differently:
memory_cache.wrap(key, function (cb) {
memory_cache.wrap(key, function(cb) {
get_user(user_id, cb);
}, function (err, user) {
}, function(err, user) {
console.log(user);
// Second time fetches user from memory_cache
memory_cache.wrap(key, function (cb) {
memory_cache.wrap(key, function(cb) {
get_user(user_id, cb);
}, function (err, user) {
}, function(err, user) {
console.log(user);

@@ -107,5 +107,5 @@ });

multi_cache.wrap(key2, function (cb) {
multi_cache.wrap(key2, function(cb) {
get_user(user_id2, cb);
}, function (err, user) {
}, function(err, user) {
console.log(user);

@@ -116,5 +116,5 @@

// the Redis cache, and set the data in memory again.
multi_cache.wrap(key2, function (cb) {
multi_cache.wrap(key2, function(cb) {
get_user(user_id2, cb);
}, function (err, user) {
}, function(err, user) {
console.log(user);

@@ -124,7 +124,7 @@ });

// Sets in all caches.
multi_cache.set('foo2', 'bar2', ttl2, function (err) {
multi_cache.set('foo2', 'bar2', ttl2, function(err) {
if (err) { throw err; }
// Fetches from highest priority cache that has the key.
multi_cache.get('foo2', function (err, result) {
multi_cache.get('foo2', function(err, result) {
console.log(result);

@@ -134,3 +134,3 @@ // >> 'bar2'

// Delete from all caches
multi_cache.del('foo2', function (err) {
multi_cache.del('foo2', function(err) {
if (err) {

@@ -137,0 +137,0 @@ console.log(err);

@@ -13,10 +13,10 @@ // Setup:

console.log("set/get/del example:");
redis_cache.set('foo', 'bar', ttl, function (err) {
redis_cache.set('foo', 'bar', ttl, function(err) {
if (err) { throw err; }
redis_cache.get('foo', function (err, result) {
redis_cache.get('foo', function(err, result) {
if (err) { throw err; }
console.log("result fetched from cache: " + result);
// >> 'bar'
redis_cache.del('foo', function (err) {
redis_cache.del('foo', function(err) {
if (err) { throw err; }

@@ -34,3 +34,3 @@ });

function get_user(id, cb) {
setTimeout(function () {
setTimeout(function() {
console.log("\n\nReturning user from slow database.");

@@ -43,3 +43,3 @@ cb(null, {id: id, name: 'Bob'});

var key = create_key(id);
redis_cache.wrap(key, function (cache_cb) {
redis_cache.wrap(key, function(cache_cb) {
get_user(user_id, cache_cb);

@@ -49,15 +49,15 @@ }, ttl, cb);

get_user_from_cache(user_id, function (err, user) {
get_user_from_cache(user_id, function(err, user) {
console.log(user);
// Second time fetches user from redis_cache
get_user_from_cache(user_id, function (err, user) {
get_user_from_cache(user_id, function(err, user) {
console.log("user from second cache request:");
console.log(user);
redis_cache.keys(function (err, keys) {
redis_cache.keys(function(err, keys) {
console.log("keys: " + util.inspect(keys));
var key = create_key(user_id);
redis_cache.del(key, function (err) {
redis_cache.del(key, function(err) {
if (err) { throw err; }

@@ -64,0 +64,0 @@ process.exit();

@@ -23,3 +23,3 @@ /**

function connect(cb) {
pool.acquire(function (err, conn) {
pool.acquire(function(err, conn) {
if (err) {

@@ -38,7 +38,7 @@ pool.release(conn);

self.get = function (key, cb) {
connect(function (err, conn) {
self.get = function(key, cb) {
connect(function(err, conn) {
if (err) { return cb(err); }
conn.get(key, function (err, result) {
conn.get(key, function(err, result) {
pool.release(conn);

@@ -51,9 +51,9 @@ if (err) { return cb(err); }

self.set = function (key, value, ttl, cb) {
self.set = function(key, value, ttl, cb) {
var ttlToUse = ttl || ttlDefault;
connect(function (err, conn) {
connect(function(err, conn) {
if (err) { return cb(err); }
if (ttlToUse) {
conn.setex(key, ttlToUse, JSON.stringify(value), function (err, result) {
conn.setex(key, ttlToUse, JSON.stringify(value), function(err, result) {
pool.release(conn);

@@ -63,3 +63,3 @@ cb(err, result);

} else {
conn.set(key, JSON.stringify(value), function (err, result) {
conn.set(key, JSON.stringify(value), function(err, result) {
pool.release(conn);

@@ -72,7 +72,7 @@ cb(err, result);

self.del = function (key, cb) {
connect(function (err, conn) {
self.del = function(key, cb) {
connect(function(err, conn) {
if (err) { return cb(err); }
conn.del(key, function (err, result) {
conn.del(key, function(err, result) {
pool.release(conn);

@@ -84,3 +84,3 @@ cb(err, result);

self.keys = function (pattern, cb) {
self.keys = function(pattern, cb) {
if (typeof pattern === 'function') {

@@ -91,6 +91,6 @@ cb = pattern;

connect(function (err, conn) {
connect(function(err, conn) {
if (err) { return cb(err); }
conn.keys(pattern, function (err, result) {
conn.keys(pattern, function(err, result) {
pool.release(conn);

@@ -106,5 +106,5 @@ cb(err, result);

module.exports = {
create: function (args) {
create: function(args) {
return redis_store(args);
}
};

@@ -0,1 +1,5 @@

- 0.16.0 2015-01-07
Get and pass up feature to update higher caches. (#19) - raadad
Minor style tweaks/jscs update.
- 0.15.0 2014-12-18

@@ -2,0 +6,0 @@ Moved cache queue before the store get function (up to 2x performance boost). (#18) - aletorrado

/*jshint maxcomplexity:15*/
var domain = require('domain');
var caching = function (args) {
var caching = function(args) {
args = args || {};

@@ -39,3 +39,3 @@ var self = {};

*/
self.wrap = function (key, work, ttl, cb) {
self.wrap = function(key, work, ttl, cb) {
if (typeof ttl === 'function') {

@@ -61,3 +61,3 @@ cb = ttl;

self.store.get(key, function (err, result) {
self.store.get(key, function(err, result) {
if (err && (!self.ignoreCacheErrors)) {

@@ -73,3 +73,3 @@ fillCallbacks(err);

})
.bind(work)(function (err, data) {
.bind(work)(function(err, data) {
if (err) {

@@ -79,3 +79,3 @@ fillCallbacks(err);

}
self.store.set(key, data, ttl, function (err) {
self.store.set(key, data, ttl, function(err) {
if (err && (!self.ignoreCacheErrors)) {

@@ -82,0 +82,0 @@ fillCallbacks(err);

@@ -7,3 +7,3 @@ var async = require('async');

*/
var multi_caching = function (caches) {
var multi_caching = function(caches) {
var self = {};

@@ -16,4 +16,4 @@ if (!Array.isArray(caches)) { throw new Error('multi_caching requires an array of caches'); }

var i = 0;
async.forEachSeries(caches, function (cache, async_cb) {
cache.store.get(key, function (err, result) {
async.forEachSeries(caches, function(cache, async_cb) {
cache.store.get(key, function(err, result) {
if (err) { return cb(err); }

@@ -32,3 +32,3 @@ if (result) {

function set_in_multiple_caches(caches, opts, cb) {
async.forEach(caches, function (cache, async_cb) {
async.forEach(caches, function(cache, async_cb) {
cache.store.set(opts.key, opts.value, opts.ttl, async_cb);

@@ -39,2 +39,24 @@ }, cb);

/**
* Looks for an item in cache tiers.
*
* When a key is found in a lower cache, all higher levels are updated
*/
self.get_and_pass_up = function(key, cb) {
get_from_highest_priority_cache(key, function(err, result, index) {
if (err) {
return cb(err);
}
cb(err, result);
if (result !== undefined && index) {
var cachesToUpdate = caches.slice(0, index);
async.forEach(cachesToUpdate, function(cache, async_cb) {
cache.set(key, result, result.ttl, async_cb);
});
}
});
};
/**
* Wraps a function in one or more caches.

@@ -49,3 +71,3 @@ * Has same API as regular caching module.

*/
self.wrap = function (key, work, ttl, cb) {
self.wrap = function(key, work, ttl, cb) {
if (typeof ttl === 'function') {

@@ -71,3 +93,3 @@ cb = ttl;

get_from_highest_priority_cache(key, function (err, result, index) {
get_from_highest_priority_cache(key, function(err, result, index) {
if (err) {

@@ -82,3 +104,3 @@ return fillCallbacks(err);

};
set_in_multiple_caches(caches_to_update, opts, function (err) {
set_in_multiple_caches(caches_to_update, opts, function(err) {
fillCallbacks(err, result);

@@ -92,3 +114,3 @@ });

})
.bind(work)(function (err, data) {
.bind(work)(function(err, data) {
if (err) {

@@ -103,3 +125,3 @@ fillCallbacks(err);

};
set_in_multiple_caches(caches, opts, function (err) {
set_in_multiple_caches(caches, opts, function(err) {
if (err) {

@@ -116,3 +138,3 @@ fillCallbacks(err);

self.set = function (key, value, ttl, cb) {
self.set = function(key, value, ttl, cb) {
var opts = {

@@ -126,8 +148,8 @@ key: key,

self.get = function (key, cb) {
self.get = function(key, cb) {
get_from_highest_priority_cache(key, cb);
};
self.del = function (key, cb) {
async.forEach(caches, function (cache, async_cb) {
self.del = function(key, cb) {
async.forEach(caches, function(cache, async_cb) {
cache.store.del(key, async_cb);

@@ -134,0 +156,0 @@ }, cb);

var Lru = require("lru-cache");
var memory_store = function (args) {
var memory_store = function(args) {
args = args || {};

@@ -15,3 +15,3 @@ var self = {};

self.set = function (key, value, ttl, cb) {
self.set = function(key, value, ttl, cb) {
lru_cache.set(key, value);

@@ -23,6 +23,6 @@ if (cb) {

self.get = function (key, cb) {
self.get = function(key, cb) {
var value = lru_cache.get(key);
if (cb) {
process.nextTick(function () {
process.nextTick(function() {
cb(null, value);

@@ -35,3 +35,3 @@ });

self.del = function (key, cb) {
self.del = function(key, cb) {
lru_cache.del(key);

@@ -43,3 +43,3 @@ if (cb) {

self.reset = function (cb) {
self.reset = function(cb) {
lru_cache.reset();

@@ -51,6 +51,6 @@ if (cb) {

self.keys = function (cb) {
self.keys = function(cb) {
var keys = lru_cache.keys();
if (cb) {
process.nextTick(function () {
process.nextTick(function() {
cb(null, keys);

@@ -67,3 +67,3 @@ });

var methods = {
create: function (args) {
create: function(args) {
return memory_store(args);

@@ -70,0 +70,0 @@ }

{
"name": "cache-manager",
"version": "0.15.0",
"version": "0.16.0",
"description": "Cache module for Node.js",

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

"istanbul": "^0.2.11",
"jscs": "^1.7.1",
"jscs": "^1.9.0",
"jshint": "^2.5.4",

@@ -32,0 +32,0 @@ "mocha": "^1.20.1",

@@ -12,3 +12,3 @@ // TODO: These are really a mix of unit and integration tests.

var methods = {
get_widget: function (name, cb) {
get_widget: function(name, cb) {
cb(null, {name: name});

@@ -18,3 +18,3 @@ }

describe("caching", function () {
describe("caching", function() {
var cache;

@@ -26,6 +26,6 @@ var key;

describe("get() and set()", function () {
['memory'].forEach(function (store) {
context("using " + store + " store", function () {
beforeEach(function () {
describe("get() and set()", function() {
['memory'].forEach(function(store) {
context("using " + store + " store", function() {
beforeEach(function() {
cache = caching({store: store});

@@ -36,6 +36,6 @@ key = support.random.string(20);

it("lets us set and get data in cache", function (done) {
cache.set(key, value, ttl, function (err) {
it("lets us set and get data in cache", function(done) {
cache.set(key, value, ttl, function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.equal(result, value);

@@ -47,5 +47,5 @@ done();

it("lets us set and get data without a callback", function (done) {
it("lets us set and get data without a callback", function(done) {
cache.set(key, value, ttl);
setTimeout(function () {
setTimeout(function() {
var result = cache.get(key);

@@ -57,5 +57,5 @@ assert.equal(result, value);

it("lets us set and get data without a ttl or callback", function (done) {
it("lets us set and get data without a ttl or callback", function(done) {
cache.set(key, value);
setTimeout(function () {
setTimeout(function() {
var result = cache.get(key);

@@ -70,10 +70,10 @@ assert.equal(result, value);

describe("del()", function () {
['memory'].forEach(function (store) {
context("using " + store + " store", function () {
beforeEach(function (done) {
describe("del()", function() {
['memory'].forEach(function(store) {
context("using " + store + " store", function() {
beforeEach(function(done) {
cache = caching({store: store});
key = support.random.string(20);
value = support.random.string();
cache.set(key, value, ttl, function (err) {
cache.set(key, value, ttl, function(err) {
check_err(err);

@@ -84,10 +84,10 @@ done();

it("deletes data from cache", function (done) {
cache.get(key, function (err, result) {
it("deletes data from cache", function(done) {
cache.get(key, function(err, result) {
assert.equal(result, value);
cache.del(key, function (err) {
cache.del(key, function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.ok(!result);

@@ -100,4 +100,4 @@ done();

it("lets us delete data without a callback", function (done) {
cache.get(key, function (err, result) {
it("lets us delete data without a callback", function(done) {
cache.get(key, function(err, result) {
assert.equal(result, value);

@@ -107,4 +107,4 @@

setTimeout(function () {
cache.get(key, function (err, result) {
setTimeout(function() {
cache.get(key, function(err, result) {
assert.ok(!result);

@@ -120,11 +120,11 @@ done();

describe("reset()", function () {
describe("reset()", function() {
var key2;
var value2;
beforeEach(function (done) {
beforeEach(function(done) {
cache = caching({store: 'memory'});
key = support.random.string(20);
value = support.random.string();
cache.set(key, value, ttl, function (err) {
cache.set(key, value, ttl, function(err) {
check_err(err);

@@ -139,10 +139,10 @@

it("clears the cache", function (done) {
cache.reset(function (err) {
it("clears the cache", function(done) {
cache.reset(function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.ok(!result);
cache.get(key2, function (err, result) {
cache.get(key2, function(err, result) {
assert.ok(!result);

@@ -155,9 +155,9 @@ done();

it("lets us clear the cache without a callback (memory store only)", function (done) {
it("lets us clear the cache without a callback (memory store only)", function(done) {
cache.reset();
setTimeout(function () {
cache.get(key, function (err, result) {
setTimeout(function() {
cache.get(key, function(err, result) {
assert.ok(!result);
cache.get(key2, function (err, result) {
cache.get(key2, function(err, result) {
assert.ok(!result);

@@ -170,14 +170,14 @@ done();

context("when store has no del() method", function () {
context("when store has no del() method", function() {
var fake_store;
beforeEach(function () {
beforeEach(function() {
fake_store = {
get: function () {},
set: function () {},
get: function() {},
set: function() {},
};
});
it("it doesn't throw an error", function () {
assert.doesNotThrow(function () {
it("it doesn't throw an error", function() {
assert.doesNotThrow(function() {
caching({store: fake_store});

@@ -189,11 +189,11 @@ });

describe("setex()", function () {
describe("setex()", function() {
var fake_store;
beforeEach(function () {
beforeEach(function() {
fake_store = {
get: function () {},
set: function () {},
del: function () {},
setex: function () {}
get: function() {},
set: function() {},
del: function() {},
setex: function() {}
};

@@ -206,3 +206,3 @@

it("passes the params to the underlying store's setex() method", function () {
it("passes the params to the underlying store's setex() method", function() {
cache.setex('foo', 'bar', 'blah');

@@ -213,7 +213,7 @@ assert.ok(fake_store.setex.calledWith('foo', 'bar', 'blah'));

describe("keys()", function () {
describe("keys()", function() {
var key_count;
var saved_keys = [];
beforeEach(function (done) {
beforeEach(function(done) {
key_count = 10;

@@ -228,3 +228,3 @@ var processed = 0;

async.until(is_done, function (cb) {
async.until(is_done, function(cb) {
processed += 1;

@@ -238,4 +238,4 @@ key = support.random.string(20);

it("calls back with all keys in cache", function (done) {
cache.keys(function (err, keys) {
it("calls back with all keys in cache", function(done) {
cache.keys(function(err, keys) {
check_err(err);

@@ -247,3 +247,3 @@ assert.deepEqual(keys.sort, saved_keys.sort);

it("lets us get the keys without a callback (memory store only)", function () {
it("lets us get the keys without a callback (memory store only)", function() {
var keys = cache.keys();

@@ -254,7 +254,7 @@ assert.deepEqual(keys.sort, saved_keys.sort);

describe("wrap()", function () {
describe("using memory (lru-cache) store", function () {
describe("wrap()", function() {
describe("using memory (lru-cache) store", function() {
var memory_store_stub;
beforeEach(function () {
beforeEach(function() {
ttl = 0.1;

@@ -270,19 +270,19 @@ memory_store_stub = memory_store.create({ttl: ttl});

afterEach(function () {
afterEach(function() {
memory_store.create.restore();
});
context("calls back with the result of the wrapped function", function () {
beforeEach(function () {
context("calls back with the result of the wrapped function", function() {
beforeEach(function() {
sinon.spy(memory_store_stub, 'set');
});
afterEach(function () {
afterEach(function() {
memory_store_stub.set.restore();
});
it("when a ttl is passed in", function (done) {
cache.wrap(key, function (cb) {
it("when a ttl is passed in", function(done) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err, widget) {
}, ttl, function(err, widget) {
check_err(err);

@@ -295,6 +295,6 @@ assert.deepEqual(widget, {name: name});

it("when a ttl is not passed in", function (done) {
cache.wrap(key, function (cb) {
it("when a ttl is not passed in", function(done) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);

@@ -308,5 +308,5 @@ assert.deepEqual(widget, {name: name});

context("when result is already cached", function () {
context("when result is already cached", function() {
function get_cached_widget(name, cb) {
cache.wrap(key, function (cache_cb) {
cache.wrap(key, function(cache_cb) {
methods.get_widget(name, cache_cb);

@@ -316,8 +316,8 @@ }, ttl, cb);

beforeEach(function (done) {
get_cached_widget(name, function (err, widget) {
beforeEach(function(done) {
get_cached_widget(name, function(err, widget) {
check_err(err);
assert.ok(widget);
memory_store_stub.get(key, function (err, result) {
memory_store_stub.get(key, function(err, result) {
check_err(err);

@@ -333,15 +333,15 @@ assert.ok(result);

afterEach(function () {
afterEach(function() {
memory_store_stub.get.restore();
});
it("retrieves data from cache", function (done) {
it("retrieves data from cache", function(done) {
var func_called = false;
cache.wrap(key, function (cb) {
methods.get_widget(name, function (err, result) {
cache.wrap(key, function(cb) {
methods.get_widget(name, function(err, result) {
func_called = true;
cb(err, result);
});
}, ttl, function (err, widget) {
}, ttl, function(err, widget) {
check_err(err);

@@ -356,10 +356,10 @@ assert.deepEqual(widget, {name: name});

it("expires cached result after ttl seconds", function (done) {
cache.wrap(key, function (cb) {
it("expires cached result after ttl seconds", function(done) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err, widget) {
}, ttl, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_store_stub.get(key, function (err, result) {
memory_store_stub.get(key, function(err, result) {
check_err(err);

@@ -370,9 +370,9 @@ assert.ok(result);

setTimeout(function () {
cache.wrap(key, function (cb) {
methods.get_widget(name, function (err, result) {
setTimeout(function() {
cache.wrap(key, function(cb) {
methods.get_widget(name, function(err, result) {
func_called = true;
cb(err, result);
});
}, function (err, widget) {
}, function(err, widget) {
check_err(err);

@@ -388,3 +388,3 @@ assert.ok(func_called);

context("when an error is thrown in the work function", function () {
context("when an error is thrown in the work function", function() {
var fake_error;

@@ -396,6 +396,6 @@

it("bubbles up that error", function (done) {
cache.wrap(key, function () {
it("bubbles up that error", function(done) {
cache.wrap(key, function() {
throw fake_error;
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, fake_error);

@@ -407,14 +407,14 @@ done();

context("when store.get() calls back with an error", function () {
context("and ignoreCacheErrors is not set (default is false)", function () {
it("bubbles up that error", function (done) {
context("when store.get() calls back with an error", function() {
context("and ignoreCacheErrors is not set (default is false)", function() {
it("bubbles up that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'get', function (key, cb) {
sinon.stub(memory_store_stub, 'get', function(key, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, fake_error);

@@ -427,4 +427,4 @@ memory_store_stub.get.restore();

context("and ignoreCacheErrors is set to true", function () {
it("does not bubble up that error", function (done) {
context("and ignoreCacheErrors is set to true", function() {
it("does not bubble up that error", function(done) {
cache = caching({store: 'memory', ttl: ttl, ignoreCacheErrors: true});

@@ -434,9 +434,9 @@

sinon.stub(memory_store_stub, 'get', function (key, cb) {
sinon.stub(memory_store_stub, 'get', function(key, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, null);

@@ -450,14 +450,14 @@ memory_store_stub.get.restore();

context("when store.set() calls back with an error", function () {
context("and ignoreCacheErrors is not set", function () {
it("bubbles up that error", function (done) {
context("when store.set() calls back with an error", function() {
context("and ignoreCacheErrors is not set", function() {
it("bubbles up that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'set', function (key, val, ttl, cb) {
sinon.stub(memory_store_stub, 'set', function(key, val, ttl, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, fake_error);

@@ -470,14 +470,14 @@ memory_store_stub.set.restore();

context("and ignoreCacheErrors is set to true", function () {
it("does not bubbles up that error", function (done) {
context("and ignoreCacheErrors is set to true", function() {
it("does not bubbles up that error", function(done) {
cache = caching({store: 'memory', ttl: ttl, ignoreCacheErrors: true});
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'set', function (key, val, ttl, cb) {
sinon.stub(memory_store_stub, 'set', function(key, val, ttl, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, null);

@@ -491,12 +491,12 @@ memory_store_stub.set.restore();

context("when wrapped function calls back with an error", function () {
it("calls back with that error", function (done) {
context("when wrapped function calls back with an error", function() {
it("calls back with that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(methods, 'get_widget', function (name, cb) {
sinon.stub(methods, 'get_widget', function(name, cb) {
cb(fake_error, {name: name});
});
cache.wrap(key, function (cb) {
cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err, widget) {
}, ttl, function(err, widget) {
methods.get_widget.restore();

@@ -511,6 +511,6 @@ assert.equal(err, fake_error);

describe("when called multiple times in parallel with same key", function () {
describe("when called multiple times in parallel with same key", function() {
var construct;
beforeEach(function () {
beforeEach(function() {
cache = caching({

@@ -522,5 +522,5 @@ store: 'memory',

construct = sinon.spy(function (val, cb) {
construct = sinon.spy(function(val, cb) {
var timeout = support.random.number(100);
setTimeout(function () {
setTimeout(function() {
cb(null, 'value');

@@ -531,3 +531,3 @@ }, timeout);

it("calls the wrapped function once", function (done) {
it("calls the wrapped function once", function(done) {
var values = [];

@@ -538,10 +538,10 @@ for (var i = 0; i < 2; i++) {

async.each(values, function (val, async_cb) {
cache.wrap('key', function (cb) {
async.each(values, function(val, async_cb) {
cache.wrap('key', function(cb) {
construct(val, cb);
}, ttl, function (err, result) {
}, ttl, function(err, result) {
assert.equal(result, 'value');
async_cb(err);
});
}, function (err) {
}, function(err) {
check_err(err);

@@ -555,4 +555,4 @@ assert.equal(construct.callCount, 1);

describe("instantiating with no store passed in", function () {
it("defaults to 'memory' store", function () {
describe("instantiating with no store passed in", function() {
it("defaults to 'memory' store", function() {
var cache = caching();

@@ -563,9 +563,9 @@ assert.equal(cache.store.name, 'memory');

describe("instantiating with custom store", function () {
it("allows us to pass in our own store object", function (done) {
describe("instantiating with custom store", function() {
it("allows us to pass in our own store object", function(done) {
var store = memory_store.create({ttl: ttl});
cache = caching({store: store});
cache.set(key, value, ttl, function (err) {
cache.set(key, value, ttl, function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.equal(result, value);

@@ -577,8 +577,8 @@ done();

it("allows us to pass in a path to our own store", function (done) {
it("allows us to pass in a path to our own store", function(done) {
var store_path = '../lib/stores/memory';
cache = caching({store: store_path});
cache.set(key, value, ttl, function (err) {
cache.set(key, value, ttl, function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.equal(result, value);

@@ -590,8 +590,8 @@ done();

it("allows us to pass in a module (uninstantiated)", function (done) {
it("allows us to pass in a module (uninstantiated)", function(done) {
var store = memory_store;
cache = caching({store: store});
cache.set(key, value, ttl, function (err) {
cache.set(key, value, ttl, function(err) {
check_err(err);
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
assert.equal(result, value);

@@ -598,0 +598,0 @@ done();

@@ -11,3 +11,3 @@ var assert = require('assert');

var methods = {
get_widget: function (name, cb) {
get_widget: function(name, cb) {
cb(null, {name: name});

@@ -17,3 +17,3 @@ }

describe("multi_caching", function () {
describe("multi_caching", function() {
var memory_cache;

@@ -28,3 +28,3 @@ var memory_cache2;

beforeEach(function () {
beforeEach(function() {
memory_ttl = 0.1;

@@ -40,6 +40,6 @@

describe("get(), set(), del()", function () {
describe("get(), set(), del()", function() {
var value;
beforeEach(function () {
beforeEach(function() {
multi_cache = multi_caching([memory_cache, memory_cache2, memory_cache3]);

@@ -50,14 +50,14 @@ key = support.random.string(20);

describe("set()", function () {
it("lets us set data in all caches", function (done) {
multi_cache.set(key, value, ttl, function (err) {
describe("set()", function() {
it("lets us set data in all caches", function(done) {
multi_cache.set(key, value, ttl, function(err) {
check_err(err);
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
assert.equal(result, value);
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.equal(result, value);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -72,15 +72,15 @@ assert.equal(result, value);

it("lets us set data without a callback", function (done) {
it("lets us set data without a callback", function(done) {
multi_cache.set(key, value, ttl);
setTimeout(function () {
multi_cache.get(key, function (err, result) {
setTimeout(function() {
multi_cache.get(key, function(err, result) {
assert.equal(result, value);
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
assert.equal(result, value);
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.equal(result, value);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -96,15 +96,15 @@ assert.equal(result, value);

it("lets us set data without a ttl or callback", function (done) {
it("lets us set data without a ttl or callback", function(done) {
multi_cache.set(key, value);
setTimeout(function () {
multi_cache.get(key, function (err, result) {
setTimeout(function() {
multi_cache.get(key, function(err, result) {
assert.equal(result, value);
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
assert.equal(result, value);
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.equal(result, value);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -121,8 +121,8 @@ assert.equal(result, value);

describe("get()", function () {
it("gets data from first cache that has it", function (done) {
memory_cache3.set(key, value, ttl, function (err) {
describe("get()", function() {
it("gets data from first cache that has it", function(done) {
memory_cache3.set(key, value, ttl, function(err) {
check_err(err);
multi_cache.get(key, function (err, result) {
multi_cache.get(key, function(err, result) {
check_err(err);

@@ -136,18 +136,18 @@ assert.equal(result, value);

describe("del()", function () {
it("lets us delete data in all caches", function (done) {
multi_cache.set(key, value, ttl, function (err) {
describe("del()", function() {
it("lets us delete data in all caches", function(done) {
multi_cache.set(key, value, ttl, function(err) {
check_err(err);
multi_cache.del(key, function (err) {
multi_cache.del(key, function(err) {
check_err(err);
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
assert.ok(!result);
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.ok(!result);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -163,4 +163,4 @@ assert.ok(!result);

it("lets us delete data without a callback", function (done) {
multi_cache.set(key, value, ttl, function (err) {
it("lets us delete data without a callback", function(done) {
multi_cache.set(key, value, ttl, function(err) {
check_err(err);

@@ -170,11 +170,11 @@

setTimeout(function () {
memory_cache.get(key, function (err, result) {
setTimeout(function() {
memory_cache.get(key, function(err, result) {
assert.ok(!result);
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.ok(!result);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -192,21 +192,109 @@ assert.ok(!result);

describe("wrap()", function () {
describe("using a single cache store", function () {
beforeEach(function () {
describe("get_and_pass_up()", function() {
var value;
var key;
describe("using a single cache store", function() {
beforeEach(function() {
multi_cache = multi_caching([memory_cache3]);
key = support.random.string(20);
value = support.random.string();
});
context("calls back with the result of a function", function () {
beforeEach(function () {
it("gets data from first cache that has it", function(done) {
memory_cache3.set(key, value, ttl, function(err) {
check_err(err);
multi_cache.get_and_pass_up(key, function(err, result) {
check_err(err);
assert.equal(result, value);
done();
});
});
});
});
describe("when value is not found in any cache", function() {
var response;
beforeEach(function(done) {
key = support.random.string(10);
sinon.spy(memory_cache, 'set');
sinon.spy(memory_cache2, 'set');
sinon.spy(memory_cache3, 'set');
multi_cache.get_and_pass_up(key, function(err, result) {
check_err(err);
response = result;
done();
});
});
afterEach(function() {
memory_cache.set.restore();
memory_cache2.set.restore();
memory_cache3.set.restore();
});
it("calls back with undefined", function() {
assert.strictEqual(response, undefined);
});
it("does not set anything in caches", function(done) {
process.nextTick(function() {
assert.ok(memory_cache.set.notCalled);
assert.ok(memory_cache2.set.notCalled);
assert.ok(memory_cache3.set.notCalled);
done();
});
});
});
describe("using multi cache store", function() {
beforeEach(function() {
multi_cache = multi_caching([memory_cache, memory_cache2, memory_cache3]);
key = support.random.string(20);
value = support.random.string();
});
it("checks to see if higher levels have item", function(done) {
memory_cache3.set(key, value, ttl, function(err) {
check_err(err);
multi_cache.get_and_pass_up(key, function(err, result) {
check_err(err);
assert.equal(result, value);
process.nextTick(function() {
memory_cache.get(key, function(err, result) {
assert.equal(result, value);
check_err(err);
done();
});
});
});
});
});
});
});
describe("wrap()", function() {
describe("using a single cache store", function() {
beforeEach(function() {
multi_cache = multi_caching([memory_cache3]);
});
context("calls back with the result of a function", function() {
beforeEach(function() {
sinon.spy(memory_cache3.store, 'set');
});
afterEach(function () {
afterEach(function() {
memory_cache3.store.set.restore();
});
it('when a ttl is passed in', function (done) {
multi_cache.wrap(key, function (cb) {
it('when a ttl is passed in', function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, ttl, function (err, widget) {
}, ttl, function(err, widget) {
check_err(err);

@@ -219,6 +307,6 @@ assert.deepEqual(widget, {name: name});

it('when a ttl is not passed in', function (done) {
multi_cache.wrap(key, function (cb) {
it('when a ttl is not passed in', function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);

@@ -232,12 +320,12 @@ assert.deepEqual(widget, {name: name});

context("when wrapped function calls back with an error", function () {
it("calls back with that error", function (done) {
context("when wrapped function calls back with an error", function() {
it("calls back with that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(methods, 'get_widget', function (name, cb) {
sinon.stub(methods, 'get_widget', function(name, cb) {
cb(fake_error, {name: name});
});
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
methods.get_widget.restore();

@@ -252,11 +340,11 @@ assert.equal(err, fake_error);

describe("using two cache stores", function () {
beforeEach(function () {
describe("using two cache stores", function() {
beforeEach(function() {
multi_cache = multi_caching([memory_cache, memory_cache3]);
});
it("calls back with the result of a function", function (done) {
multi_cache.wrap(key, function (cb) {
it("calls back with the result of a function", function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);

@@ -268,14 +356,14 @@ assert.deepEqual(widget, {name: name});

it("sets value in all caches", function (done) {
multi_cache.wrap(key, function (cb) {
it("sets value in all caches", function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
check_err(err);
assert.deepEqual(result, {name: name});
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -289,14 +377,14 @@ assert.deepEqual(result, {name: name});

context("when value exists in first store but not second", function () {
it("returns value from first store, does not set it in second", function (done) {
memory_cache.set(key, {name: name}, ttl, function (err) {
context("when value exists in first store but not second", function() {
it("returns value from first store, does not set it in second", function(done) {
memory_cache.set(key, {name: name}, ttl, function(err) {
check_err(err);
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -311,14 +399,14 @@ assert.equal(result, null);

context("when value exists in second store but not first", function () {
it("returns value from second store, sets it in first store", function (done) {
memory_cache3.set(key, {name: name}, ttl, function (err) {
context("when value exists in second store but not first", function() {
it("returns value from second store, sets it in first store", function(done) {
memory_cache3.set(key, {name: name}, ttl, function(err) {
check_err(err);
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
check_err(err);

@@ -334,11 +422,11 @@ assert.deepEqual(result, {name: name});

describe("using three cache stores", function () {
beforeEach(function () {
describe("using three cache stores", function() {
beforeEach(function() {
multi_cache = multi_caching([memory_cache, memory_cache3, memory_cache2]);
});
it("calls back with the result of a function", function (done) {
multi_cache.wrap(key, function (cb) {
it("calls back with the result of a function", function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);

@@ -350,18 +438,18 @@ assert.deepEqual(widget, {name: name});

it("sets value in all caches", function (done) {
multi_cache.wrap(key, function (cb) {
it("sets value in all caches", function(done) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
check_err(err);
assert.deepEqual(result, {name: name});
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.deepEqual(result, {name: name});
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -376,18 +464,18 @@ assert.deepEqual(result, {name: name});

context("when value exists in first store only", function () {
it("returns value from first store, does not set it in second or third", function (done) {
memory_cache.set(key, {name: name}, ttl, function (err) {
context("when value exists in first store only", function() {
it("returns value from first store, does not set it in second or third", function(done) {
memory_cache.set(key, {name: name}, ttl, function(err) {
check_err(err);
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);
assert.equal(result, null);
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);

@@ -403,18 +491,18 @@ assert.equal(result, null);

context("when value exists in second store only", function () {
it("returns value from second store, sets it in first store, does not set third store", function (done) {
memory_cache3.set(key, {name: name}, ttl, function (err) {
context("when value exists in second store only", function() {
it("returns value from second store, sets it in first store, does not set third store", function(done) {
memory_cache3.set(key, {name: name}, ttl, function(err) {
check_err(err);
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
check_err(err);
assert.deepEqual(result, {name: name});
memory_cache2.get(key, function (err, result) {
memory_cache2.get(key, function(err, result) {
check_err(err);

@@ -430,18 +518,18 @@ assert.equal(result, null);

context("when value exists in third store only", function () {
it("returns value from third store, sets it in first and second stores", function (done) {
memory_cache2.set(key, {name: name}, ttl, function (err) {
context("when value exists in third store only", function() {
it("returns value from third store, sets it in first and second stores", function(done) {
memory_cache2.set(key, {name: name}, ttl, function(err) {
check_err(err);
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
}, function(err, widget) {
check_err(err);
assert.deepEqual(widget, {name: name});
memory_cache3.get(key, function (err, result) {
memory_cache3.get(key, function(err, result) {
check_err(err);
assert.deepEqual(result, {name: name});
memory_cache.get(key, function (err, result) {
memory_cache.get(key, function(err, result) {
check_err(err);

@@ -459,7 +547,7 @@ assert.deepEqual(result, {name: name});

context("error handling", function () {
context("error handling", function() {
var memory_store_stub;
var ttl;
beforeEach(function () {
beforeEach(function() {
ttl = 0.1;

@@ -472,7 +560,7 @@ memory_store_stub = memory_store.create({ttl: ttl});

afterEach(function () {
afterEach(function() {
memory_store.create.restore();
});
context("when an error is thrown in the work function", function () {
context("when an error is thrown in the work function", function() {
var fake_error;

@@ -484,6 +572,6 @@

it("bubbles up that error", function (done) {
multi_cache.wrap(key, function () {
it("bubbles up that error", function(done) {
multi_cache.wrap(key, function() {
throw fake_error;
}, ttl, function (err) {
}, ttl, function(err) {
assert.equal(err, fake_error);

@@ -495,13 +583,13 @@ done();

context("when store.get() calls back with an error", function () {
it("bubbles up that error", function (done) {
context("when store.get() calls back with an error", function() {
it("bubbles up that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'get', function (key, cb) {
sinon.stub(memory_store_stub, 'get', function(key, cb) {
cb(fake_error);
});
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err) {
}, function(err) {
assert.equal(err, fake_error);

@@ -514,13 +602,13 @@ memory_store_stub.get.restore();

context("when store.set() calls back with an error", function () {
it("bubbles up that error", function (done) {
context("when store.set() calls back with an error", function() {
it("bubbles up that error", function(done) {
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'set', function (key, val, ttl, cb) {
sinon.stub(memory_store_stub, 'set', function(key, val, ttl, cb) {
cb(fake_error);
});
multi_cache.wrap(key, function (cb) {
multi_cache.wrap(key, function(cb) {
methods.get_widget(name, cb);
}, function (err) {
}, function(err) {
assert.equal(err, fake_error);

@@ -534,11 +622,11 @@ memory_store_stub.set.restore();

describe("when called multiple times in parallel with same key", function () {
describe("when called multiple times in parallel with same key", function() {
var construct;
beforeEach(function () {
beforeEach(function() {
multi_cache = multi_caching([memory_cache, memory_cache3]);
construct = sinon.spy(function (val, cb) {
construct = sinon.spy(function(val, cb) {
var timeout = support.random.number(100);
setTimeout(function () {
setTimeout(function() {
cb(null, 'value');

@@ -549,3 +637,3 @@ }, timeout);

it("calls the wrapped function once", function (done) {
it("calls the wrapped function once", function(done) {
var values = [];

@@ -556,10 +644,10 @@ for (var i = 0; i < 5; i++) {

async.each(values, function (val, async_cb) {
multi_cache.wrap('key', function (cb) {
async.each(values, function(val, async_cb) {
multi_cache.wrap('key', function(cb) {
construct(val, cb);
}, function (err, result) {
}, function(err, result) {
assert.equal(result, 'value');
async_cb(err);
});
}, function (err) {
}, function(err) {
check_err(err);

@@ -573,5 +661,5 @@ assert.equal(construct.callCount, 1);

context("when instantiated with a non-Array 'caches' arg", function () {
it("throws an error", function () {
assert.throws(function () {
context("when instantiated with a non-Array 'caches' arg", function() {
it("throws an error", function() {
assert.throws(function() {
multi_caching({foo: 'bar'});

@@ -578,0 +666,0 @@ }, /multi_caching requires an array/);

@@ -28,3 +28,3 @@ #!/usr/bin/env node

valid_test_types.forEach(function (valid_test_type) {
valid_test_types.forEach(function(valid_test_type) {
if (requested_types.indexOf(valid_test_type) !== -1) {

@@ -40,3 +40,3 @@ types_to_use.push(valid_test_type);

var is_valid_file = function (file) {
var is_valid_file = function(file) {
if (file.match(/buster/)) {

@@ -59,6 +59,6 @@ return false;

function run(cb) {
walk_dir('test', is_valid_file, function (err, files) {
walk_dir('test', is_valid_file, function(err, files) {
if (err) { return cb(err); }
files.forEach(function (file) {
files.forEach(function(file) {
mocha.addFile(file);

@@ -71,7 +71,7 @@ });

run(function (err) {
run(function(err) {
if (err) { throw err; }
mocha.run(function (failures) {
mocha.run(function(failures) {
process.exit(failures);
});
});
var support = require('../support');
var memory_store = require('../../lib/stores/memory');
describe("memory store", function () {
describe("instantiating", function () {
it("lets us pass in no args", function (done) {
describe("memory store", function() {
describe("instantiating", function() {
it("lets us pass in no args", function(done) {
var memory_cache = memory_store.create();

@@ -8,0 +8,0 @@ support.test_set_get_del(memory_cache, done);

@@ -7,3 +7,3 @@ var fs = require('fs');

random: {
string: function (str_len) {
string: function(str_len) {
str_len = str_len || 8;

@@ -19,3 +19,3 @@ var chars = "abcdefghiklmnopqrstuvwxyz";

number: function (max) {
number: function(max) {
max = max || 1000;

@@ -26,3 +26,3 @@ return Math.floor((Math.random() * max));

check_err: function (err) {
check_err: function(err) {
if (err) {

@@ -44,3 +44,3 @@ var msg;

assert_between: function (actual, lower, upper) {
assert_between: function(actual, lower, upper) {
assert.ok(actual >= lower, "Expected " + actual + " to be >= " + lower);

@@ -50,3 +50,3 @@ assert.ok(actual <= upper, "Expected " + actual + " to be <= " + upper);

assert_within: function (actual, expected, delta) {
assert_within: function(actual, expected, delta) {
var lower = expected - delta;

@@ -57,3 +57,3 @@ var upper = expected + delta;

walk_dir: function (dir, validation_function, cb) {
walk_dir: function(dir, validation_function, cb) {
if (arguments.length === 2) {

@@ -65,3 +65,3 @@ cb = validation_function;

var results = [];
fs.readdir(dir, function (err, list) {
fs.readdir(dir, function(err, list) {
if (err) { return cb(err); }

@@ -73,7 +73,7 @@

list.forEach(function (file) {
list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function (err, stat) {
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
support.walk_dir(file, validation_function, function (err, res) {
support.walk_dir(file, validation_function, function(err, res) {
results = results.concat(res);

@@ -98,3 +98,3 @@ if (!--pending) { cb(null, results); }

test_set_get_del: function (cache, cb) {
test_set_get_del: function(cache, cb) {
var key = 'TEST' + support.random.string();

@@ -104,13 +104,13 @@ var val = support.random.string();

cache.set(key, val, ttl, function (err) {
cache.set(key, val, ttl, function(err) {
if (err) { return cb(err); }
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
if (err) { return cb(err); }
assert.equal(result, val);
cache.del(key, function (err) {
cache.del(key, function(err) {
if (err) { return cb(err); }
cache.get(key, function (err, result) {
cache.get(key, function(err, result) {
if (err) { return cb(err); }

@@ -117,0 +117,0 @@ assert.ok(!result);

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