Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use max-age header to set ttl #3

Open
eschwartz opened this issue Jul 21, 2016 · 1 comment
Open

Use max-age header to set ttl #3

eschwartz opened this issue Jul 21, 2016 · 1 comment

Comments

@eschwartz
Copy link

It looks like CrispHttpCache is only looking at the the s-maxage header to set TTLs:

main.js:234
if (cacheControlInfo['s-maxage'] && !isPrivate) {
  return callback(null, parseInt(cacheControlInfo['s-maxage']) * 1000);
}

I would think that should be:

const maxAge = cacheControlInfo['s-maxage'] || cacheControlInfo['max-age'];
if (maxAge && !isPrivate) {
  return callback(null, parseInt(cacheControlInfo['s-maxage']) * 1000);
}
@four43
Copy link
Owner

four43 commented Jul 21, 2016

Background

max-age is a portion of the Cache-Control header that directs a cache, in the most specific case, a client's local cache. The s- prefix is for "shared" and is an instruction for shared proxies. Sensitive data specific to a single user will use a max-age header of however long, while setting the s-maxage to 0, denoting that proxies in the middle of the request should not cache sensitive data. In theory someone should have set the private portion, but crisp-http-cache was designed to play it safe in the instance someone forgot. The cache itself is a shared cache so we respect s-maxage primarily.

Change

According to the spec:

The max-age directive on a response implies that the response is cacheable (i.e., "public") unless some other, more restrictive cache directive is also present.
(via https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3)

We should also respect max-age and its assumed public-ness.

Good catch, @eschwartz

P.S. It also bugs me that max-age is properly "kebab case" where s-maxage has no second hyphen, as would be expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants