Skip to content

Commit

Permalink
Merge branch 'release/0.14.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Oct 15, 2014
2 parents 3355d95 + 6c7d2d1 commit 13eb093
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 32 deletions.
80 changes: 80 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],

"requireSpaceBeforeBinaryOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowSpaceAfterBinaryOperators": ["!"],
"disallowSpaceBeforeBinaryOperators": [","],

"disallowMultipleVarDecl": true,
"disallowEmptyBlocks": true,
"disallowKeywords": ["with"],
"disallowKeywordsOnNewLine": ["else"],
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"disallowMultipleLineStrings": true,
"disallowTrailingWhitespace": true,
"disallowPaddingNewlinesInBlocks": true,

"requireCommaBeforeLineBreak": true,

"requireParenthesesAroundIIFE": true,

"requireSpaceBeforeBlockStatements": true,

"requireSpacesInConditionalExpression": true,

"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},

"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],

"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],

"safeContextKeyword": "self",

"validateIndentation": 4,
"validateParameterSeparator": ", ",

"excludeFiles": [
"test/data/**",
"test/support/fakes/**"
],
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},

"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"disallowYodaConditions": true
}
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- 0.14.0 2014-10-15
Set ttl in wrap #14 - nguyenchr
Added JSCS for style checking

- 0.13.0 2014-10-14
Applied work function locking for multi_caching (#13). -aletorrado

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test-travis: lint
./node_modules/.bin/istanbul cover test/run.js --report lcovonly \
-- -T unit,functional -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
lint:
./node_modules/.bin/jscs ./lib && \
./node_modules/.bin/jscs ./test && \
./node_modules/.bin/jscs ./examples && \
./node_modules/.bin/jshint ./lib --config $(BASE)/.jshintrc && \
./node_modules/.bin/jshint ./test --config $(BASE)/.jshintrc
./node_modules/.bin/jshint ./examples --config $(BASE)/.jshintrc
Expand Down
6 changes: 3 additions & 3 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*jshint unused:false*/
// Note: ttls are in seconds
var cache_manager = require('../');
var memory_cache = cache_manager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});
var memory_cache2 = cache_manager.caching({store: 'memory', max: 100, ttl: 100/*seconds*/});
var memory_cache = cache_manager.caching({store: 'memory', max: 100, ttl: 10});
var memory_cache2 = cache_manager.caching({store: 'memory', max: 100, ttl: 100});
var ttl; //Can't use a different ttl per set() call with memory cache

//
Expand Down Expand Up @@ -74,7 +75,6 @@ get_cached_user(user_id, function (err, user) {
// { id: 123, name: 'Bob' }
// { id: 123, name: 'Bob' }


// Same as above, but written differently:
memory_cache.wrap(key, function (cb) {
get_user(user_id, cb);
Expand Down
3 changes: 2 additions & 1 deletion examples/redis_example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
var util = require('util');
var cache_manager = require('../../');
var redis_store = require('./redis_store');
var redis_cache = cache_manager.caching({store: redis_store, db: 0, ttl: 100/*seconds*/});
// Note: ttl is in seconds
var redis_cache = cache_manager.caching({store: redis_store, db: 0, ttl: 100});
var ttl = 60;

console.log("set/get/del example:");
Expand Down
10 changes: 4 additions & 6 deletions lib/caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ var caching = function (args) {
* });
*/
self.wrap = function (key, work, ttl, cb) {

if(typeof(ttl) == 'function') {
cb = ttl;
ttl = undefined;
if (typeof ttl === 'function') {
cb = ttl;
ttl = undefined;
}

self.store.get(key, function (err, result) {
Expand Down Expand Up @@ -66,8 +65,7 @@ var caching = function (args) {
self.queues[key].forEach(function (done) {
done.call(null, err);
});
}
else {
} else {
self.queues[key].forEach(function (done) {
done.apply(null, work_args);
});
Expand Down
25 changes: 12 additions & 13 deletions lib/multi_caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ var multi_caching = function (caches) {
* cache, it gets set in all higher-priority caches.
*/
self.wrap = function (key, work, ttl, cb) {

if(typeof(ttl) == 'function') {
cb = ttl;
ttl = undefined;
if (typeof ttl === 'function') {
cb = ttl;
ttl = undefined;
}

get_from_highest_priority_cache(key, function (err, result, index) {
Expand All @@ -54,9 +53,9 @@ var multi_caching = function (caches) {
} else if (result) {
var caches_to_update = caches.slice(0, index);
var opts = {
key: key,
value: result,
ttl: ttl
key: key,
value: result,
ttl: ttl
};
set_in_multiple_caches(caches_to_update, opts, function (err) {
cb(err, result);
Expand All @@ -75,9 +74,9 @@ var multi_caching = function (caches) {
return;
}
var opts = {
key: key,
value: work_args[1],
ttl: ttl
key: key,
value: work_args[1],
ttl: ttl
};
set_in_multiple_caches(caches, opts, function (err) {
if (err) {
Expand All @@ -99,9 +98,9 @@ var multi_caching = function (caches) {

self.set = function (key, value, ttl, cb) {
var opts = {
key: key,
value: value,
ttl: ttl
key: key,
value: value,
ttl: ttl
};
set_in_multiple_caches(caches, opts, cb);
};
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cache-manager",
"version": "0.13.0",
"version": "0.14.0",
"description": "Cache module for Node.js",
"main": "index.js",
"scripts": {
Expand All @@ -26,7 +26,8 @@
"devDependencies": {
"coveralls": "^2.3.0",
"istanbul": "^0.2.11",
"jshint": "^2.5.1",
"jscs": "^1.7.1",
"jshint": "^2.5.4",
"mocha": "^1.20.1",
"optimist": "^0.6.1",
"sinon": "^1.10.2"
Expand Down
7 changes: 2 additions & 5 deletions test/caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ describe("caching", function () {
});

context("calls back with the result of the wrapped function", function () {

beforeEach(function () {
sinon.spy(memory_store_stub, 'set');
});
Expand All @@ -260,7 +259,7 @@ describe("caching", function () {
memory_store_stub.set.restore();
});

it("when a ttl is passed in", function(done) {
it("when a ttl is passed in", function (done) {
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, ttl, function (err, widget) {
Expand All @@ -269,10 +268,9 @@ describe("caching", function () {
sinon.assert.calledWith(memory_store_stub.set, key, {name: name}, ttl);
done();
});

});

it("when a ttl is not passed in", function(done) {
it("when a ttl is not passed in", function (done) {
cache.wrap(key, function (cb) {
methods.get_widget(name, cb);
}, function (err, widget) {
Expand All @@ -282,7 +280,6 @@ describe("caching", function () {
done();
});
});

});

context("when result is already cached", function () {
Expand Down
2 changes: 0 additions & 2 deletions test/multi_caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ describe("multi_caching", function () {
});

context("calls back with the result of a function", function () {

beforeEach(function () {
sinon.spy(memory_cache3.store, 'set');
});
Expand Down Expand Up @@ -215,7 +214,6 @@ describe("multi_caching", function () {
done();
});
});

});

context("when wrapped function calls back with an error", function () {
Expand Down

0 comments on commit 13eb093

Please sign in to comment.