IPC München, 24. Oktober 2016
httpstatusdogs.com
1 | GET /path |
2 | Accept-Encoding: text/html |
1 | HTTP/1.1 200 OK |
2 | Content-Type: text/html |
3 |
4 | <html>...</html> |
twitter.com/stevelosh/status/372740571749572610
HTTP 1.1, RFC 2616, Kapitel 13.2 und 13.3
1 | Cache-Control: s-maxage=3600, max-age=900 |
2 | Expires: Thu, 15 May 2014 08:00:00 GMT |
ETag: 82901821233
If-None-Match: 82901821233
304 Not Modified
1 | Cache-Control: s-maxage=0, private, no-cache |
www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0 (Varnish 3)
www.varnish-cache.org/trac/browser/bin/varnishd/builtin.vcl?rev=4.0 (Varnish 4)
1 | GET /resource |
2 | Accept: application/json |
1 | GET /resource |
2 | Accept: text/xml |
1 | Vary: Accept |
Varnish macht genau das,
was du ihm sagst
Bitte genau aufpassen und gut testen
1 | sub vcl_backend_response { |
2 | set beresp.http.TTL = beresp.ttl; |
3 | } |
01 | sub vcl_deliver { |
02 | # If X-Varnish contains only 1 id, we have |
03 | # a miss, if it contains more (and |
04 | # therefore a space), we have a hit. |
05 |
06 | if (resp.http.X-Varnish ~ " ") { |
07 | set resp.http.Debug-Cache = "HIT"; |
08 | } else { |
09 | set resp.http.Debug-Cache = "MISS"; |
10 | } |
11 | } |
01 | backend default { |
02 | .host = "127.0.0.1"; .port = "8080";} |
03 | backend legacy { |
04 | .host = "127.0.0.1"; .port = "8000";} |
05 |
06 | sub vcl_recv { |
07 | if (req.url ~ "^/archive/") { |
08 | set req.backend_hint = legacy; |
09 | } else { |
10 | set req.backend_hint = default; |
11 | } |
12 | } |
1 | < link rel = "stylesheet" href = "/css/style.css?v1" type = "text/css" /> |
2 | ... |
3 | < script src = "/js/scripts.js?v1" ></ script > |
01 | acl invalidators { |
02 | "localhost"; |
03 | } |
04 |
05 | if (req.method == "PURGE") { |
06 | if (!client.ip ~ invalidators) { |
07 | return (synth(405, "Not allowed")); |
08 | } |
09 | return (purge); |
10 | } |
11 |
12 | ... |
01 | vcl_backend_response { |
02 | set beresp.http.X-Url = bereq.url; |
03 | set beresp.http.X-Host = bereq.http.host; |
04 | } |
05 |
06 | vcl_recv { |
07 | if (req.method == "BAN") { |
08 | if (!client.ip ~ invalidators) { |
09 | return (synth(405, "Not allowed")); |
10 | } |
11 | ban("obj.http.X-Host ~ " + req.http.X-Host |
12 | + " && obj.http.X-Url ~ " + req.http.X-Url |
13 | ); |
14 | } |
15 | } |
1 | $response ->withHeader( 'X-Cache-Tags' , 'id-42' ); |
1 | ban("obj.http.x-cache-tags ~ " |
2 | + req.http.x-cache-tags |
3 | ); |
1 | /** @var $cm CacheManageer */ |
2 | $cm ->tagResponse( $response , array ( 'id-42' )); |
3 | ... |
4 | $cm ->invalidateTags( array ( 'id-42' )); |
1 | use FOS\HttpCacheBundle\Configuration\Tag; |
2 | class CommentController extends Controller { |
3 | /** |
4 | * @Tag({"comments", "'comment-'~id"}) |
5 | */ |
6 | public function commentAction( $id ) |
7 | // ... |