Skip to content

Commit

Permalink
Using fs.stats mtime in gzippo cached object to negate the need to in…
Browse files Browse the repository at this point in the history
…stantiate a new date object
  • Loading branch information
tomgco committed Jul 20, 2011
1 parent 63e26cd commit 81f8104
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/staticGzip.js
Expand Up @@ -92,7 +92,7 @@ exports = module.exports = function staticGzip(dirPath, options){
res.setHeader('Content-Encoding', 'gzip');
res.setHeader('Vary', 'Accept-Encoding');
res.setHeader('Content-Length', cacheObj.content.length);
res.setHeader('Last-Modified', new Date(cacheObj.mtime).toUTCString());
res.setHeader('Last-Modified', cacheObj.mtime.toUTCString());
res.setHeader('Date', new Date().toUTCString());
res.setHeader('Expires', new Date(Date.now() + clientMaxAge).toUTCString());
res.setHeader('Cache-Control', 'public, max-age=' + (clientMaxAge / 1000));
Expand All @@ -108,7 +108,7 @@ exports = module.exports = function staticGzip(dirPath, options){
gzippo(filename, charset, function(gzippedData) {
gzippoCache[gzipName] = {
'ctime': Date.now(),
'mtime': new Date(mtime).getTime(),
'mtime': mtime,
'content': gzippedData
};
sendGzipped(gzippoCache[gzipName]);
Expand Down Expand Up @@ -159,11 +159,11 @@ exports = module.exports = function staticGzip(dirPath, options){

//TODO: check for pre-compressed file
if (typeof gzippoCache[gzipName] === 'undefined') {
gzipAndSend(filename, gzipName, stat.mtime.toUTCString());
gzipAndSend(filename, gzipName, stat.mtime);
} else {
if ((gzippoCache[gzipName].mtime < stat.mtime) ||
((gzippoCache[gzipName].ctime + maxAge) < Date.now())) {
gzipAndSend(filename, gzipName, stat.mtime.toUTCString());
gzipAndSend(filename, gzipName, stat.mtime);
} else {
sendGzipped(gzippoCache[gzipName]);
}
Expand Down

0 comments on commit 81f8104

Please sign in to comment.