Skip to content

Commit

Permalink
made stags cache optional with the cache option
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Mar 4, 2014
1 parent 681c9ed commit 6cf04a6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/cabinet.js
Expand Up @@ -212,7 +212,8 @@ var send = exports.send = function(req, res, next, options, cache, virtuals, wat
//
// Get cached stats object from file meta cache (if we hit no IO is required)
//
metaCache.get(path).then(function(meta){
metaCache.get(path, !options.cache).then(function(meta){

//
// If the file does not exist we call the next middleware.
//
Expand All @@ -237,7 +238,6 @@ var send = exports.send = function(req, res, next, options, cache, virtuals, wat
// non-cached transfer.
//
if(!sendFromCache(req, res, path)){

// "hidden" file
if (!hidden && '.' == basename(path)[0]) return next();

Expand Down Expand Up @@ -357,6 +357,7 @@ var send = exports.send = function(req, res, next, options, cache, virtuals, wat
* @api private
*/
function setResponseHeaders(path, res, stat, etag, contentType){
res.setHeader('X-Powered-By', 'Cabinet');
if (!res.getHeader('Accept-Ranges')) res.setHeader('Accept-Ranges', 'bytes');
if (!res.getHeader('ETag')) res.setHeader('ETag', etag || getEtag(stat));
if (!res.getHeader('Date')) res.setHeader('Date', new Date().toUTCString());
Expand All @@ -368,6 +369,7 @@ var send = exports.send = function(req, res, next, options, cache, virtuals, wat
if (!res.getHeader('Content-Type')) {
res.setHeader('Content-Type', utils.getContentType(path));
}

}

/**
Expand Down Expand Up @@ -662,9 +664,10 @@ var send = exports.send = function(req, res, next, options, cache, virtuals, wat
sendEntry(req, res, entry);
})
}else{
entry = [];
entry.headers = _.clone(res._headers);
entry.data.push(data);
entry = {
headers: _.clone(res._headers),
data: [data]
};
sendEntry(req, res, entry);
}
});
Expand Down

0 comments on commit 6cf04a6

Please sign in to comment.