You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kornel Lesiński
c07f89dfff
|
9 years ago | |
---|---|---|
test | 9 years ago | |
.gitignore | 9 years ago | |
README.md | 9 years ago | |
index.js | 9 years ago | |
package.json | 9 years ago |
README.md
HTTP cache semantics
CachePolicy
object that computes properties of a HTTP response, such as whether it's fresh or stale, and how long it can be cached for. Based on RFC 7234.
Usage
const cache = new CachePolicy(request, response, options);
// Age counts from the time response has been created
const secondsFresh = cache.maxAge();
const secondsOld = cache.age();
// Current state
const currentState = cache.isFresh();
Cacheability of response depends on how it was requested, so both request and response are required. Both are objects with headers
property that is an object with lowercased header names as keys, e.g.
const request = {
method: 'GET',
headers: {
'accept': '*/*',
},
};
const response = {
status: 200,
headers: {
'cache-control': 'public, max-age=7234',
},
};
const options = {
shared: true,
};
If options.shared
is true (default), then response is evaluated from perspective of a shared cache (i.e. private
is not cacheable and s-maxage
is respected). If options.shared
is false, then response is evaluated from perspective of a single-user cache (i.e. private
is cacheable and s-maxage
is ignored).
Implemented
Expires
with check for bad clocksCache-Control
response headerPragma
response headerAge
response header
Unimplemented
- Request properties are not evaluated
Vary
support is as lame and incomplete as in web browsers- No support for revalidation and stale responses