jshttp / fresh

HTTP request freshness testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inadvertent reverse of 'no-cache' and 'no-store'

hakrac opened this issue · comments

commented

As stated in the MDN docs the no-cache directive is used indicate that the client has a copy in the cache but needs to validate it with each request. no-store on the other hand will disable all caches.

no-cache
Forces caches to submit the request to the origin server for validation before releasing a cached copy.

This means that fresh should give back true inconjuction with theses headers:
var reqHeaders = {
"if-none-match": "foo",
"cache-control" : "no-cache"
};

var resHeaders = {
"etag" : "foo"
};

correct me if I'm wrong;

Can you link to the MDN article you are referencing?

At least based on what you pasted

Forces caches to submit the request to the origin server for validation before releasing a cached copy.

The behavior of this module is correct; true = fresh and false = stale.

What you pasted says that it should bust the cache, right? As in this module should state stale (false), not fresh (true).

Issue #16 has more background if it helps.

commented

Here is the MDN article as well as a Google developer article which explains http caching.

fresh should give back true but it didn't (if Etag header and if-none-match header match, client cache is fresh)

No-store would mean that there is nothing in the cache, which makes the request stale, doesn't it?

var reqHeaders = {
"if-none-match": "bar",
"cache-control" : "no-store"
};

var resHeaders = {
"etag" : "bar"
};

fresh(reqHeaders, resHeaders); -> true

There are two different Cache-Control headers: one for requests and one for responses. This module only reads the Cache-Control for requests, not responses. The MDN article is only for the Cache-Control response header, which is not relevant here. That controls the behavior of the web client (browser) not the web server (node.js). There are different directives for each side with different meanings.

The Google article linked is also only the Cache-Control response header, not the request header.