Skip to content

Commit

Permalink
Merge pull request #20 from teohhanhui/cache-control
Browse files Browse the repository at this point in the history
Use Cache-Control max-age instead of Expires header
  • Loading branch information
teohhanhui authored Jul 14, 2016
2 parents 8af6501 + e5a2f06 commit 6a4cac3
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/streams/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ function ResponseWriter(request, response){
util.inherits(ResponseWriter, stream.Writable);


ResponseWriter.prototype.expiresIn = function(maxAge){
var dt = Date.now();
dt += maxAge * 1000;

return (new Date(dt)).toGMTString();
};


ResponseWriter.prototype.shouldCacheResponse = function(){
if (env.development){
if (env.CACHE_DEV_REQUESTS){
Expand Down Expand Up @@ -61,10 +53,7 @@ ResponseWriter.prototype._write = function(image){
if (image.modifiers.action === 'json'){
if (this.shouldCacheResponse()){
this.response.set({
'Cache-Control': 'public',
'Expires': this.expiresIn(env.JSON_EXPIRY),
'Last-Modified': (new Date(1000)).toGMTString(),
'Vary': 'Accept-Encoding'
'Cache-Control': 'max-age=' + String(image.expiry)
});
}

Expand All @@ -76,10 +65,7 @@ ResponseWriter.prototype._write = function(image){

if (this.shouldCacheResponse()){
this.response.set({
'Cache-Control': 'public',
'Expires': this.expiresIn(image.expiry),
'Last-Modified': (new Date(1000)).toGMTString(),
'Vary': 'Accept-Encoding'
'Cache-Control': 'max-age=' + String(image.expiry)
});
}

Expand Down

0 comments on commit 6a4cac3

Please sign in to comment.