New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

catbox

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catbox - npm Package Compare versions

Comparing version 4.2.2 to 4.3.0

2

examples/policy.js

@@ -64,2 +64,2 @@ // After starting this example load http://localhost:8080 and hit refresh, you will notice that it loads the response from cache for the first 5 seconds and then reloads the cache. Look at the console to see it setting and getting items from cache.

internals.startCache(internals.startServer);
internals.startCache(internals.startServer);

@@ -353,1 +353,11 @@ // Load modules

};
internals.Policy.prototype.isReady = function () {
if (!this._cache) {
return false;
}
return this._cache.connection.isReady();
};
{
"name": "catbox",
"description": "Multi-strategy object caching service",
"version": "4.2.2",
"version": "4.3.0",
"repository": "git://github.com/hapijs/catbox",
"main": "index",
"main": "lib/index.js",
"keywords": [

@@ -23,10 +23,6 @@ "cache"

"scripts": {
"test": "make test-cov"
"test": "lab -a code -t 100 -L",
"test-cov-html": "lab -a code -r html -o coverage.html"
},
"licenses": [
{
"type": "BSD",
"url": "http://github.com/hapijs/catbox/raw/master/LICENSE"
}
]
"license": "BSD-3-Clause"
}

@@ -8,3 +8,3 @@ ![catbox Logo](https://raw.github.com/hapijs/catbox/master/images/catbox.png)

Lead Maintainer: [Ben Acker](https://github.com/nvcexploder)
Lead Maintainer: [Eran Hammer](https://github.com/hueniverse)

@@ -57,5 +57,5 @@ **catbox** is a multi-strategy key-value object store. It comes with extensions supporting a memory cache,

If found, the `cached` object contains the following:
- `item` - the value stored in the cache using `set()`.
- `stored` - the timestamp when the item was stored in the cache (in milliseconds).
- `ttl` - the remaining time-to-live (not the original value used when storing the object).
- `item` - the value stored in the cache using `set()`.
- `stored` - the timestamp when the item was stored in the cache (in milliseconds).
- `ttl` - the remaining time-to-live (not the original value used when storing the object).
- `set(key, value, ttl, callback)` - store an item in the cache for a specified length of time, where:

@@ -87,7 +87,7 @@ - `key` - a cache key object (see below).

signature is `function(id, next)` where:
- `id` - the `id` string or object provided to the `get()` method.
- `next` - the method called when the new item is returned with the signature `function(err, value, ttl)` where:
- `err` - an error condition.
- `value` - the new value generated.
- `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the cache. Defaults to the cache global policy.
- `id` - the `id` string or object provided to the `get()` method.
- `next` - the method called when the new item is returned with the signature `function(err, value, ttl)` where:
- `err` - an error condition.
- `value` - the new value generated.
- `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the cache. Defaults to the cache global policy.
- `staleIn` - number of milliseconds to mark an item stored in cache as stale and attempt to regenerate it when `generateFunc` is

@@ -138,3 +138,4 @@ provided. Must be less than `expiresIn`. Alternatively function that returns staleIn value in miliseconds. The function signature is

- `ttl(created)` - given a `created` timestamp in milliseconds, returns the time-to-live left based on the configured rules.
- `rules(options) - changes the policy rules after construction (note that items already stored will not be affected) where:
- `rules(options)` - changes the policy rules after construction (note that items already stored will not be affected) where:
- `options` - the same `options` as the `Policy` constructor.
- `isReady()` - returns `true` if cache engine determines itself as ready, `false` if it is not ready or if there is no cache engine set.

@@ -95,9 +95,27 @@ // Load modules

var errorEngine = {
start: function (callback) { callback(null); },
start: function (callback) {
callback(null);
},
stop: function () { },
isReady: function () { return true; },
validateSegmentName: function () { return null; },
get: function (key, callback) { return callback(new Error('fail')); },
set: function (key, value, ttl, callback) { return callback(new Error('fail')); },
drop: function (key, callback) { return callback(new Error('fail')); }
isReady: function () {
return true;
},
validateSegmentName: function () {
return null;
},
get: function (key, callback) {
return callback(new Error('fail'));
},
set: function (key, value, ttl, callback) {
return callback(new Error('fail'));
},
drop: function (key, callback) {
return callback(new Error('fail'));
}
};

@@ -104,0 +122,0 @@

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

policy.set('x', '123', null, function (err) {
expect(err).to.not.exist();

@@ -103,2 +104,3 @@

policy.set('x', '123', 1000, function (err) {
expect(err).to.not.exist();

@@ -304,3 +306,3 @@

expect(value).to.equal('item');
expect(cached.isStale).to.be.false;
expect(cached.isStale).to.be.false();
done();

@@ -446,3 +448,6 @@ });

var client = new Catbox.Client(Import, { partition: 'test-partition' });
client.get = function (key, callback) { callback(new Error('bad client')); };
client.get = function (key, callback) {
callback(new Error('bad client'));
};
var policy = new Catbox.Policy(rule, client, 'test-segment');

@@ -834,2 +839,3 @@

setTimeout(function () {
policy.get('test', function (err, value2, cached) {

@@ -882,2 +888,3 @@

setTimeout(function () {
policy.get('test', function (err, value2, cached) {

@@ -887,3 +894,3 @@

expect(err).to.be.instanceOf(Error);
expect(value2).to.be.undefined; // Stale
expect(value2).to.be.undefined(); // Stale

@@ -893,3 +900,3 @@ policy.get('test', function (err, value3, cached) {

expect(err).to.be.instanceOf(Error);
expect(value3).to.be.undefined; // Stale
expect(value3).to.be.undefined(); // Stale
done();

@@ -933,2 +940,3 @@ });

setTimeout(function () {
policy.get('test', function (err, value2, cached) {

@@ -938,3 +946,3 @@

expect(err).to.be.instanceOf(Error);
expect(value2).to.be.undefined; // Stale
expect(value2).to.be.undefined(); // Stale

@@ -944,3 +952,3 @@ policy.get('test', function (err, value3, cached) {

expect(err).to.be.instanceOf(Error);
expect(value3).to.be.undefined; // Stale
expect(value3).to.be.undefined(); // Stale
done();

@@ -1247,3 +1255,3 @@ });

next(null, { gen: ++gen });
}, 5)
}, 5);
}

@@ -1259,4 +1267,4 @@ };

orig.call(client.connection, key, callback)
}, 10)
orig.call(client.connection, key, callback);
}, 10);
};

@@ -1281,4 +1289,4 @@

client.connection.get = orig;
done()
})
done();
});
});

@@ -1873,4 +1881,45 @@ }, 21);

});
});
describe('isReady()', function () {
it('returns cache engine readiness', function (done) {
var expected = true;
var engine = {
start: function (callback) {
callback();
},
isReady: function () {
return expected;
},
get: function (key, callback) {
callback(new Error());
},
validateSegmentName: function () {
return null;
}
};
var client = new Catbox.Client(engine);
var policy = new Catbox.Policy({}, client, 'test');
client.start(function () {
expect(policy.isReady()).to.equal(expected);
done();
});
});
it('returns false when no cache client provided', function (done) {
var policy = new Catbox.Policy({ expiresIn: 1 });
expect(policy.isReady()).to.equal(false);
done();
});
});
});
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