WHO AM I • Alistair Stead - @alistairstead • Technical Team Lead @ Ibuildings UK / Session Digital • Lead Magento projects for Dreams, 3663, Kookai and others • Author of MageTool and MageTest • Zend Certified Engineer • Over 11 years commercial experience developing in PHP Monday, 6 June 2011
USE VARNISH WITH MAGENTO Add shared cache to reduce the load on the application Client Browser Varnish Port 80 Backend Apache Port 8080 Monday, 6 June 2011
sub vcl_recv { set req.http.Surrogate-Capability = "magento=ESI/1.0"; return (lookup); } sub vcl_fetch { if (beresp.http.Surrogate-Control ~ "ESI/1.0") { # unset beresp.http.Surrogate-Control; esi; } return (deliver); } sub vcl_deliver { # Set a cache header to allow us to inspect the response # headers during testing if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; set resp.http.X-Cache-Hits = obj.hits; } else { set resp.http.X-Cache = "MISS"; } } Monday, 6 June 2011
/** * Render the html for the ESI tag * * @return string * @author Alistair Stead **/ public function getHtml() { return sprintf( '', $this->getAttributeHash() ); } Monday, 6 June 2011
VARNISH LIMITATIONS • Does not currently support GZIP • Cookies need to be managed carefully • Still need SSL endpoint • Routing and URL generation can be tricky • Beware cache stampede • ESI must have a TTL greater than the parent page • Shared cache consider using s-maxage with max-age Monday, 6 June 2011