Skip to content

Commit f55f0b3

Browse files
author
Kevin Whitley
committed
Added middleware toggle as 2nd param for caching middleware
1 parent 17b0e70 commit f55f0b3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/apicache.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function ApiCache() {
6969
}
7070
};
7171

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

@@ -88,9 +88,9 @@ function ApiCache() {
8888
return function cache(req, res, next) {
8989
var cached;
9090

91-
if (!globalOptions.enabled || req.headers['x-apicache-bypass']) {
91+
if (!globalOptions.enabled || req.headers['x-apicache-bypass'] || (_.isFunction(middlewareToggle) && !middlewareToggle(req, res))) {
9292
if (globalOptions.debug && req.headers['x-apicache-bypass']) {
93-
console.log('[api-cache]: header "x-apicache-bypass" detected, skipping cache.');
93+
console.log('[api-cache]: bypass detected, skipping cache.');
9494
}
9595
return next();
9696
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apicache",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"description": "An ultra-simplified API/JSON response caching middleware for Express/Node using plain-english durations.",
55
"main": "./lib/apicache.js",
66
"repository": {

0 commit comments

Comments
 (0)