Wed 06 Jan 2016 — Wed 06 Mar 2019
Nginx
Nginx can cache static files it serves using expires 1h;
inside a location block.
It can also cache proxied requests using proxy_cache
. This is a slightly complicated thing which involves setting up a zone and a key.
HTTP
- Cache-Control header:
- public/private
- can anywhere (e.g. CDN or ISP) vs only cache in the browser.
- no-store
- never use the cache.
- no-cache
- always ask the server for the etag. If it matches, use the cache.
- max-age=<seconds>
- we can use the cached resource for this long. Afterwards, we need to check the etag to renew the cache.
- s-maxage=<seconds>
- an override for CDNs.
- don't use this. Cache-Control takes precedence. However, in Nginx you configure the Cache-Control header using the
expires
directive. - a hash identifying a resource. This will be checked against the server's etag when a cached file hits its expiry time.
- specify headers which the cache will vary over.
- ignore this. Olden days.