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.3.0 to 0.4.0

4

History.md

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

- 0.4.0 2014-05-02
New arg to ignore cache errors. if set cache errors will be ignored
and the cache_manager will go to the backing store. (Thanks londonjamo).
- 0.3.0 2013-12-08

@@ -2,0 +6,0 @@ Bound the get, set and del functions to their original “this” context when assigning a store.

7

lib/caching.js

@@ -17,2 +17,5 @@ var caching = function (args) {

// do we handle a cache error the same as a cache miss?
self.ignoreCacheErrors = args.ignoreCacheErrors || false;
/**

@@ -34,3 +37,3 @@ * Wraps a function in cache. I.e., the first time the function is run,

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

@@ -46,3 +49,3 @@ return cb(null, result);

self.store.set(key, work_args[1], function (err) {
if (err) { return cb(err); }
if (err && (!self.ignoreCacheErrors)) { return cb(err); }
cb.apply(null, work_args);

@@ -49,0 +52,0 @@ });

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

@@ -5,0 +5,0 @@ "main": "index.js",

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

cache = caching({store: 'memory', ttl: ttl});
cache = caching({store: 'memory', ttl: ttl, ignoreCacheErrors: false});
key = support.random.string(20);

@@ -191,15 +191,37 @@ name = support.random.string();

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());
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) {
cb(fake_error);
sinon.stub(memory_store_stub, 'get', function (key, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, fake_error);
memory_store_stub.get.restore();
done();
});
});
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, fake_error);
memory_store_stub.get.restore();
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});
var fake_error = new Error(support.random.string());
sinon.stub(memory_store_stub, 'get', function (key, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, null);
memory_store_stub.get.restore();
done();
});
});

@@ -210,15 +232,36 @@ });

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());
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, cb) {
cb(fake_error);
sinon.stub(memory_store_stub, 'set', function (key, val, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, fake_error);
memory_store_stub.set.restore();
done();
});
});
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, fake_error);
memory_store_stub.set.restore();
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, cb) {
cb(fake_error);
});
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err) {
assert.equal(err, null);
memory_store_stub.set.restore();
done();
});
});

@@ -225,0 +268,0 @@ });

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