Skip to content

Commit

Permalink
Doc fix version bump and remove latent semi colons
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison Higham committed Feb 20, 2015
1 parent 5f4ddce commit 5eb5cbe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,7 +50,7 @@ cacher.on("error", function(err) {
})

// Dev mode, quickly turn off caching when it gets in the way
var env = process.env.NODE_ENV || 'development';
var env = process.env.NODE_ENV || 'development'
if (env === 'development') {
cacher.noCaching = true
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cacher.js
Expand Up @@ -101,7 +101,7 @@ function checkNoCache(toCheck) {

Cacher.prototype.cache = function(unit, value) {
var ttl = this.calcTtl(unit, value),
self = this;
self = this

return function(req, res, next) {
// set noCaching to true in dev mode to get around stale data when you don't want it
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cacher",
"version": "2.1.0",
"version": "2.1.1",
"description": "A memcached backed http cache in the form of express middleware",
"main": "index.js",
"scripts": {
Expand Down
80 changes: 40 additions & 40 deletions test/testCacher.js
Expand Up @@ -87,28 +87,28 @@ describe('Cacher', function() {
})

describe('Override TTL based on response', function() {
var cacher = new Cacher(new Client());
var app = express();
var errorCodes = [ 400, 401, 403, 404, 500, 504 ];
var cacher = new Cacher(new Client())
var app = express()
var errorCodes = [ 400, 401, 403, 404, 500, 504 ]

app.get('/error', cacher.cache('minute'), function(req, res) {
var code = Number(req.param('code')) || 400;
res.send('kaboom', code);
});
var code = Number(req.param('code')) || 400
res.send('kaboom', code)
})

beforeEach(function() {
// clear '/error?code=*' entries from cache before each test.
errorCodes.forEach(function(httpErrorStatusCode) {
cacher.invalidate('/error?code=' + httpErrorStatusCode);
});
});
cacher.invalidate('/error?code=' + httpErrorStatusCode)
})
})

it('should return unaltered TTL by default, regardless of response statusCode', function(done) {
assert.strictEqual(cacher.genCacheTtl({ statusCode: 200 }, 60), 60);
assert.strictEqual(cacher.genCacheTtl({ statusCode: 200 }, 60), 60)

async.each(
errorCodes, function(httpErrorStatusCode, next) {
assert.strictEqual(cacher.genCacheTtl({ statusCode: httpErrorStatusCode }, 60), 60);
assert.strictEqual(cacher.genCacheTtl({ statusCode: httpErrorStatusCode }, 60), 60)

supertest(app)
.get('/error')
Expand All @@ -117,7 +117,7 @@ describe('Cacher', function() {
.expect(httpErrorStatusCode, 'kaboom')
.expect('Content-Type', /text/)
.end(function(err, res) {
assert.ifError(err);
assert.ifError(err)

supertest(app)
.get('/error')
Expand All @@ -126,28 +126,28 @@ describe('Cacher', function() {
.expect(httpErrorStatusCode, 'kaboom')
.expect('Content-Type', /text/)
.end(function(err, res) {
assert.ifError(err);
next();
});
});
assert.ifError(err)
next()
})
})
}, done
);
});
)
})

it('should use custom TTL on error responses when genCacheTtl is overridden', function(done) {
// Override TTL for error responses to be 0 (i.e. not cached).
cacher.genCacheTtl = function(res, origTtl) {
if (errorCodes.indexOf(res.statusCode) >= 0) {
return 0;
return 0
}
return origTtl;
};
return origTtl
}

assert.strictEqual(cacher.genCacheTtl({ statusCode: 200 }, 60), 60);
assert.strictEqual(cacher.genCacheTtl({ statusCode: 200 }, 60), 60)

async.each(
errorCodes, function(httpErrorStatusCode, next) {
assert.strictEqual(cacher.genCacheTtl({ statusCode: httpErrorStatusCode }, 60), 0);
assert.strictEqual(cacher.genCacheTtl({ statusCode: httpErrorStatusCode }, 60), 0)

supertest(app)
.get('/error')
Expand All @@ -156,7 +156,7 @@ describe('Cacher', function() {
.expect(httpErrorStatusCode, 'kaboom')
.expect('Content-Type', /text/)
.end(function(err, res) {
assert.ifError(err);
assert.ifError(err)

supertest(app)
.get('/error')
Expand All @@ -165,14 +165,14 @@ describe('Cacher', function() {
.expect(httpErrorStatusCode, 'kaboom')
.expect('Content-Type', /text/)
.end(function(err, res) {
assert.ifError(err);
next();
});
});
assert.ifError(err)
next()
})
})
}, done
);
});
});
)
})
})

describe('Caching', function() {
var cacher = new Cacher(new Client())
Expand Down Expand Up @@ -476,25 +476,25 @@ describe('Cacher', function() {
.expect(cacher.cacheHeader, expectedCache)
.expect(200, 'foo')
.end(function(err, res) {
assert.ifError(err);
assert.ifError(err)

supertest(app)
.get('/barMount/nodupe')
.expect(cacher.cacheHeader, expectedCache)
.expect(200, 'bar')
.end(function(err, res) {
assert.ifError(err);
next();
});
});
};
assert.ifError(err)
next()
})
})
}

async.series([
function(next) { collisionTest('false', next) },
function(next) { collisionTest('true', next) },
function() { done(); }
]);
});
function() { done() }
])
})

})
})

0 comments on commit 5eb5cbe

Please sign in to comment.