Skip to content

Commit

Permalink
Added middleware toggle as 2nd param for caching middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Whitley committed Jan 27, 2014
1 parent 17b0e70 commit f55f0b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/apicache.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function ApiCache() {
}
};

this.middleware = function cache(duration) {
this.middleware = function cache(duration, middlewareToggle) {
if (typeof duration === 'string') {
var split = duration.match(/^(\d+)\s(\w+)$/);

Expand All @@ -88,9 +88,9 @@ function ApiCache() {
return function cache(req, res, next) {
var cached;

if (!globalOptions.enabled || req.headers['x-apicache-bypass']) {
if (!globalOptions.enabled || req.headers['x-apicache-bypass'] || (_.isFunction(middlewareToggle) && !middlewareToggle(req, res))) {
if (globalOptions.debug && req.headers['x-apicache-bypass']) {
console.log('[api-cache]: header "x-apicache-bypass" detected, skipping cache.');
console.log('[api-cache]: bypass detected, skipping cache.');
}
return next();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apicache",
"version": "0.0.11",
"version": "0.0.12",
"description": "An ultra-simplified API/JSON response caching middleware for Express/Node using plain-english durations.",
"main": "./lib/apicache.js",
"repository": {
Expand Down

0 comments on commit f55f0b3

Please sign in to comment.