diff options
Diffstat (limited to 'src/node/utils')
-rw-r--r-- | src/node/utils/caching_middleware.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/node/utils/caching_middleware.js b/src/node/utils/caching_middleware.js index f25059b8..61be733a 100644 --- a/src/node/utils/caching_middleware.js +++ b/src/node/utils/caching_middleware.js @@ -23,7 +23,9 @@ var zlib = require('zlib'); var util = require('util'); var ROOT_DIR = path.normalize(__dirname + "/../"); -var CACHE_DIR = ROOT_DIR + '../var/'; +var CACHE_DIR = path.normalize(ROOT_DIR + '../../var/'); +console.log(CACHE_DIR) +CACHE_DIR = path.existsSync(CACHE_DIR) ? CACHE_DIR : undefined; var responseCache = {}; @@ -37,7 +39,7 @@ function CachingMiddleware() { } CachingMiddleware.prototype = new function () { function handle(req, res, next) { - if (!(req.method == "GET" || req.method == "HEAD")) { + if (!(req.method == "GET" || req.method == "HEAD") || !CACHE_DIR) { return next(undefined, req, res); } @@ -54,7 +56,7 @@ CachingMiddleware.prototype = new function () { var modifiedSince = (req.headers['if-modified-since'] && new Date(req.headers['if-modified-since'])); var lastModifiedCache = !error && stats.mtime; - if (lastModifiedCache) { + if (lastModifiedCache && responseCache[cacheKey]) { req.headers['if-modified-since'] = lastModifiedCache.toUTCString(); } else { delete req.headers['if-modified-since']; |