| Author | Kacper Wysocki | 
| Contact | |
| Date | November 24, 2010 | 
sweet architecture
really REALLY high loads
flexible control and transparency
can make things more secure too

Usually we use varnish to:
scale a website
fix header stuff
hack around application issues

setup varnish
apt-get install varnish yum install varnish
NEED Varnish 2.x
WANT Varnish 2.1
watch out for the 32 bits

what to cache
how to cache
purging pages
edge side includes

do this now:
backend mine {
  .host = "my backend";
  .port = "80";
}
EVERYTHING!
Cache-control: public, max-age=180
Cache-control: public, smax-age=300, max-age=180
must-revalidate ; no-cache

Last-Modified + Expires
Age:
Pragma: no-cache
Etags hash

avoid cookies
delete cookies
send reasonable header => automagic!
browser cache too!

identify static content
/css, /js, /images, /static etc
what dynamic pages can be cached?
NEVER cache another man's content
avoid redirects :-P

there are two hard problems in CS
lazy, so-called "bans"
purge on url, header, other conditions
deletes from cache

telnet, purge_url
HTTP PURGE + acl
GET /foo/bar?purge=true
cache-channels
fix your app to expire cache automagically!
purge req.url ~ "/foo"
purge req.http.user-agent ~ "Firefox" &&
      obj.http.content-type ~ "text"
purge("req.url == " req.url);
Benefits:
paste together sites
cache what can be cached
dynamic fragments of pages
same content (frame, img src,..) in many places
Limitations:
must be defined backend!
small subset of real ESI
no gzip, deflate, ssl (but fixable with nginx)
session workspace
sub vcl_fetch {
   if(obj.http.content-type ~ "text/html"){
     esi;
   }
}
<html> <body> Foobar <esi:include src="http://kwy.u.bitbit.net/"> <esi:include src="/cgi-bin/date.cgi"> </body>

<esi:include src="/must/be/reachable/thru/backends/"> <esi:remove>not shown if ESI on</esi:remove> <!--esi not shown if ESI is off -->
kacper.blog.linpro.no
kwy.u.bitbit.net
6BD0 3F9C 5F77 AD24 F60A 86EC FD82 7E34 674A 506F
References: http://www.varnish-cache.org/trac/wiki