Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added header option to force a fetch but not bypassing the store. #17

Merged
merged 3 commits into from
Aug 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/apicache.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function ApiCache() {
}
// In Express 4.x the url is ambigious based on where a router is mounted. originalUrl will give the full Url
var key = req.originalUrl || req.url;

// Remove querystring from key if jsonp option is enabled
if (globalOptions.jsonp) {
key = url.parse(key).pathname;
Expand All @@ -131,7 +131,7 @@ function ApiCache() {
cached = memCache.get(key);
}

if (cached || globalOptions.redisClient) {
if ((cached || globalOptions.redisClient) && !req.headers['x-apicache-force-fetch']) {

if (!globalOptions.redisClient) {

Expand Down Expand Up @@ -187,9 +187,9 @@ function ApiCache() {
}

res.realSend = (globalOptions.jsonp) ? res.jsonp : res.send;

var methodName = (globalOptions.jsonp) ? "jsonp" : "send";

res[methodName] = function(a, b) {
var responseObj = {
headers: {
Expand All @@ -211,7 +211,7 @@ function ApiCache() {
}

index.all.push(key);

if (globalOptions.debug) {
console.log('[api-cache]: adding cache entry for "' + key + '" @ ' + duration + ' milliseconds');
}
Expand Down