httpstatusdogs.com
GET /path
Accept-Encoding: text/html
HTTP/1.1 200 OK
Content-Type: text/html
<html>...</html>
twitter.com/stevelosh/status/372740571749572610
HTTP 1.1, RFC 2616, Sections 13.2 and 13.3
Cache-Control: s-maxage=3600, max-age=900
Expires: Thu, 15 May 2014 08:00:00 GMT
ETag: 82901821233
If-None-Match: 82901821233
304 Not Modified
Cache-Control: stale-while-revalidate=3600;
Cache-Control: stale-if-error=3600;
Cache-Control: must-revalidate;
Cache-Control: s-maxage=0, private, no-cache
Entête pour gérer vos substituts differament des caches inconnues
Cache-Control: no-store
Surrogate-Control: max-age=3600
Réponse depends des certains entêtes de la requête
GET /resource
Accept: application/json
GET /resource
Accept: text/xml
Vary: Accept
api_platform:
defaults:
cache_headers:
max_age: 0
shared_max_age: 3600
vary: ['Content-Type','Authorization','Origin']
Attention avec Vary: Authorization
use ApiPlatform\Metadata\ApiResource;
#[ApiResource(
cacheHeaders: [
'max_age' => 60,
'shared_max_age' => 120,
'vary' => ['Accept-Language']
]
)]
class Book
{
// ...
}
#[ApiResource]
#[Get(
cacheHeaders: [
'max_age' => 60,
'shared_max_age' => 120
]
)]
$response->setCache([
'max-age' => 300,
]);
$response->headers
->addCacheControlDirective('must_revalidate');
$response->headers
->addCacheControlDirective('stale_if_error', 3600);
<link rel="stylesheet" href="/css/style.css?v1" type="text/css"/>
...
<script src="/js/scripts.js?v1"></script>
Varnish: Purge/Refresh, Ban, xkey
$response->withHeader('xkey', 'news id42 id44');
xkey.purge(req.http.xkey-purge);
Si on fait avec BAN, c'est beaucoup moins efficace.
| Element  | weight |  <->  | Element  | weight |
|---|---|---|---|---|
| A | 9 | D | 22 | |
| B | 8 | A | 9 | |
| C | 7 | B | 8 | |
| D | 6 | C | 7 | |
| E | 5 | E | 5 | |
| F | 4 | F | 4 | |
| G | 3 | G | 3 | |
| H | 2 | H | 2 | |
| I | 1 | I | 1 |
| Element  | weight |  <->  | Element  | weight |
|---|---|---|---|---|
| A | 9 | A | 9 | |
| B | 8 | B | 8 | |
| C | 7 | D | 6 | |
| D | 6 | E | 5 | |
| E | 5 | F | 4 | |
| F | 4 | G | 3 | |
| G | 3 | H | 2 | |
| H | 2 | I | 1 | |
| I | 1 |
{
"total_hits":3,
"products":[
<esi:include src="/products/1071.json" />,
<esi:include src="/products/1305.json" />,
<esi:include src="/products/1311.json" />
]
}
TTL trés bas pour les listes, invalidation active que pour les entrées
sub vcl_recv {
if (req.esi_level > 0) {
set req.http.doing-esi = "yes";
}
}
sub vcl_backend_response {
# retry backend errors during esi
if (bereq.http.doing-esi && beresp.status >= 500) {
# sleep between 1 and 30 ms to spread the load
vtc.sleep(std.duration(std.random(0.001,0.03), 0.02s));
return(retry);
}
}
sub vcl_backend_response {
if (bereq.http.doing-esi && beresp.http.Content-Length) {
# Disable streaming to validate the content-length
set beresp.do_stream = false;
}
}
sub vcl_backend_error {
# retry fetch errors during esi
# respect retry limit to still reach vcl_deliver
if (bereq.http.doing-esi && beresp.status == 503
&& bereq.retries < 4
) {
vtc.sleep(std.duration(std.random(0.001,0.03), 0.02s));
return(retry);
}
}
sub vcl_deliver {
if (req.http.doing-esi && resp.status >= 400) {
return (synth(758, "Ignore ESI error"));
}
}
sub vcl_synth {
if (resp.status == 758) {
set resp.http.Content-Type =
"application/json; charset=utf-8";
set resp.status = 200;
# need space after " before } to not confuse Varnish
synthetic({"{"failed_product":""} + req.url + {"" }"});
std.syslog(3, "ESI kept failing for "+req.url);
return (deliver);
}
}