Varnish Caching Proxy


Madison PHP Conference
September 13th, 2014

© David Buchmann, Liip AG

Step 1

apt-get install varnish
            

Step 2

service apache2 restart
service varnish restart
            

Step 3

What could possibly go wrong?

What is a reverse proxy again?

HTTP is simple

GET /path

HTTP/1.1 200 OK
Content-Type: text/html

<html>...</html>
            

HTTP verbs

HTTP response codes

https://twitter.com/stevelosh/status/372740571749572610

Default Varnish behaviour

http://httpstatusdogs.com

Cache control headers

Cache-Control: s-maxage=3600, max-age=900
Expires: Thu, 15 May 2014 08:00:00 GMT
            
  1. s-maxage
  2. max-age
  3. Expires
  4. Default to default_ttl if nothing specified

Do not cache

Cache-Control: s-maxage=0, private, no-cache
            

Keep variants apart

Request

Accept: application/json
            

Response

Vary: Accept
            

Cache validation (the new way)

ETag: 82901821233
            
If-None-Match: 82901821233

304 Not Modified