-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I'm thinking it would be nice if Cacher supported Cache-Control: max-age, Cache-Control: s-maxage, and Expires headers out of the box.
I've added support for this in my own application by overriding the genCacheTtl function, but I could submit this feature as a pull request, if you'd like. Here's what my implementation looks like:
var parseCacheControl = require('parse-cache-control');
var cacher = new Cacher();
cacher.genCacheTtl = function(res, origTtl) {
if (res.get('Cache-Control')) {
var cacheControl = parseCacheControl(res.get('Cache-Control'));
if (cacheControl['s-maxage']) {
return parseInt(cacheControl['s-maxage']);
}
if (cacheControl['max-age']) {
return parseInt(cacheControl['max-age']);
}
}
if (res.get('Expires')) {
return (Date.parse(res.get('Expires')) - Date.now()) / 1000;
}
return origTtl;
};
I've read just a little bit about cache control headers, and from what I understand the order of precedence goes:
Cache-Control: s-maxageCache-Control: max-ageCache-Control: Expires
Metadata
Metadata
Assignees
Labels
No labels