Varnish

12,198 views

Published on

Published in: Technology
6 Comments
63 Likes
Statistics
Notes
No Downloads
Views
Total views
12,198
On SlideShare
0
From Embeds
0
Number of Embeds
1,120
Actions
Shares
0
Downloads
32
Comments
6
Likes
63
Embeds 0
No embeds

No notes for slide

Varnish

  1. 1. Varnish 3 The easy wayto speed up your websites @fabpot fabien@symfony.comhttp://www.flickr.com/photos/laserstars/908946494
  2. 2. Varnish is an HTTP accelerator http://www.flickr.com/photos/stuckincustoms/3232133635
  3. 3. Varnish is a Caching Reverse Proxy http://www.flickr.com/photos/stuckincustoms/3232133635
  4. 4. Kinds of caches http://www.flickr.com/photos/jnarin/2993803017
  5. 5. Browser Browser BrowserBrowser Cache Browser Cache Browser Cache Within a Company On the server side Your PHP application
  6. 6. Browser Browser Browser Browser Browser BrowserBrowser Cache Browser Cache Browser Cache Browser Cache Browser Cache Browser Cache Proxy Cache Proxy Cache Within a Company Within a Company On the server side Your PHP application
  7. 7. Browser Browser Browser Browser BrowserBrowser Cache Browser Cache Browser Cache Browser Cache Browser Cache Proxy Cache Within a Company On the server side Reverse Proxy Cache Your PHP application
  8. 8. HTTP and Caching http://www.flickr.com/photos/hdz/5623651313
  9. 9. RFC 2616 – HTTP/1.1http://www.ietf.org/rfc/rfc2616.txt http://tools.ietf.org/wg/httpbis/
  10. 10. The Client sends a Request to the ServerThe Server sends back a Response to the Client A Client (browser, bot, WS, curl, …) A Server (Apache, nginx, …)The Request and the Response are HTTP messages
  11. 11. GET / HTTP/1.1Host: http.trainings.sensiolabs.com
  12. 12. HTTP/1.1 200 OKDate: Wed, 15 Oct 2005 07:07:07 GMTServer: ApacheContent-Length: 14Content-Type: text/htmlHello World!
  13. 13. Caching in the HTTP Specification
  14. 14.  p1: Messaging: Low-level message parsing and connection management p2: Semantics: Methods, status codes and headers p3: Payload: Dealing with content, message-specific headers p4: Conditional Requests: e.g., If-Modified-Since p5: Range Requests: Getting partial content p6: Caching: Browser and intermediary caches p7: Authentication: HTTP authentication framework
  15. 15. ExpirationCache-Control Expires
  16. 16. ValidationLast-Modified / If-Modified-Since ETag / If-None-Match
  17. 17. The goal is to nevergenerate the same response twice http://www.flickr.com/photos/donaldmacleod/3439612846
  18. 18. HTTP Expiration
  19. 19. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Cache-­‐Control:  s-­‐maxage=10 Hello Hello
  20. 20. Before expiration GET /foo HTTP/1.1 Your application is not called Host: foo.org Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK Hello
  21. 21. After expiration GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Some Cache fresh Your PHP application NotBrowser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Cache-Control: s-maxage=10 Hello Hello
  22. 22. HTTP Validation
  23. 23. Last-Modified / If-Modified-Since Etag / If-None-Match
  24. 24. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Last-Modified: Thu,   … Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Last-Modified: Thu,  … Last-Modified: Thu,  … Hello Hello
  25. 25. If the resource has not changed GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-Modified-Since: Thu, Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Last-Modified: Thu,   … Hello HTTP/1.1 200 OK HTTP/1.1 304 Not Modified Last-Modified: Thu,  … Hello
  26. 26. If the resource has changed GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-Modified-Since: Thu, Your PHP application Some CacheBrowser GET /foo /foo GET HTTP/1.1 200 200 OK HTTP/1.1 OK Last-Modified: Sun,… Last-Modified: Thu,… Hello Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Last-Modified: Sun,  … Last-Modified: Sun,  … Hello Hello
  27. 27. You can combine HTTP headers the way you wantExpiration wins over Validation
  28. 28. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK HTTP/1.1 200 OK ETag: abcdef ETag: abcdef Cache-­‐Control:  max-­‐age=10 Cache-­‐Control:  max-­‐age=10 Hello Hello
  29. 29. Before expiration GET /foo HTTP/1.1 Host: foo.org Your application is not called Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK ETag: abcdef Cache-­‐Control:  max-­‐age=10 Hello
  30. 30. After expiration but resource still valid GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-None-Match: abcdef Your PHP application Some CacheBrowser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK HTTP/1.1 304 Not Modified ETag: abcdef Cache-­‐Control:  max-­‐age=10 Cache-­‐Control:  max-­‐age=10 Hello
  31. 31. HTTP Expiration
  32. 32. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Bob’s Cache … … Hello HelloBob HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 C-C: max-age=600 Hello Hello Hello
  33. 33. GET /foo HTTP/1.1 Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Bob’s Cache … … Hello HelloBob HTTP/1.1 200 OK C-C: max-age=600 Hello
  34. 34. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Browser Cache C-C: max-age=600 C-C: max-age=600 … … Hello HelloAlice HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Hello Hello
  35. 35. HTTP Validation
  36. 36. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: abcde Etag: abcde Bob’s Cache … … Hello HelloBob HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: abcde Etag: abcde Etag: abcde Hello Hello Hello
  37. 37. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org If-None-Match: ab If-None-Match: ab Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab Bob’s Cache … … Hello HelloBob HTTP/1.1 200 OK Etag: ab 304 Not Modified 304 Not Modified Hello
  38. 38. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org If-None-Match: ab Your PHP application Reverse Proxy Cache GET /foo GET /foo Browser Cache HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab … … Hello HelloAlice HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab 304 Not Modified Hello Hello
  39. 39. VCLVarnish Configuration Language http://www.flickr.com/photos/akatayama/84707813
  40. 40. backend default { .host = "127.0.0.1"; .port = "8080";}
  41. 41. pipe vcl_pipe error vcl_error restart deliver orkflow lookup deliverRequest vcl_recv vcl_hash W cached? vcl_hit pass vcl_deliver Response deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  42. 42. Special Subroutines
  43. 43. req. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  44. 44. if (req.restarts == 0) { if (req.http.x-forwarded-for) { set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip; } else { set req.http.X-Forwarded-For = client.ip; }}if (req.request != "GET" && req.request != "HEAD" && req.request !="PUT" && req.request != "POST" && req.request != "TRACE" &&req.request != "OPTIONS" && req.request != "DELETE") { return (pipe);}if (req.request != "GET" && req.request != "HEAD") { return (pass);}if (req.http.Authorization || req.http.Cookie) { return (pass);}return (lookup);
  45. 45. req. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  46. 46. hash_data(req.url);if (req.http.host) { hash_data(req.http.host);} else { hash_data(server.ip);}return (hash);
  47. 47. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  48. 48. req. obj. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  49. 49. return (deliver);
  50. 50. req. bereq. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  51. 51. return (fetch);
  52. 52. req. bereq. beresp. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  53. 53. if (beresp.ttl <= 0s || beresp.http.Set-Cookie ||beresp.http.Vary == "*") { set beresp.ttl = 120 s; return (hit_for_pass);}return (deliver);
  54. 54. resp. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  55. 55. return (deliver);
  56. 56. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  57. 57. set obj.http.Content-Type = "text/html; charset=utf-8";set obj.http.Retry-After = "5";synthetic {"<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>"} + obj.status + " " + obj.response + {"</title></head><body><h1>Error "} + obj.status + " " + obj.response + {"</h1><p>"} + obj.response + {"</p><h3>Guru Meditation:</h3><p>XID: "} + req.xid + {"</p><hr><p>Varnish cache server</p></body></html>"};return (deliver);
  58. 58. Varnish Workflowhttp://www.flickr.com/photos/w4nd3rl0st/6604159789
  59. 59. lookupRequest vcl_recv vcl_hash cached? vcl_deliver Response deliver fetch vcl_miss vcl_fetch
  60. 60. lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response
  61. 61. pipe vcl_pipeRequest vcl_recv Response
  62. 62. lookupRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver vcl_miss vcl_fetch pass vcl_pass pass
  63. 63. pipe vcl_pipe error vcl_error restart deliver lookup deliverRequest vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  64. 64. VCL Recipes http://www.flickr.com/photos/christijohnstone/5474556299
  65. 65. backend default { .host = "127.0.0.1"; .port = "8080";}sub vcl_recv{ if ((req.request == "GET" || req.request == "HEAD") && req.url ~ ".(png|gif|jpg|swf|css|js)$") { unset req.http.cookie; return(lookup); }}sub vcl_fetch{ if (req.url ~ ".(png|gif|jpg|swf|css|js)$") { remove beresp.http.set-cookie; set beresp.ttl = 2h; }}
  66. 66. sub vcl_hit{ if (...) { if (obj.hits >= 10) { set obj.ttl = obj.ttl * 2; } }}
  67. 67. backend app { .host = "192.168.0.1"; .port = "8080";}backend images { .host = "192.168.0.2"; .port = "8080";}
  68. 68. sub vcl_recv{ set req.backend = app; if (req.url ~ ".(gif|jpg|swf|css|js)$") { set req.backend = images; }}
  69. 69. sub vcl_deliver{ set resp.http.X-Cache = obj.hits+" "+req.backend;}
  70. 70. sub vcl_recv { if (req.http.host ~ "^(?i)example.org" && req.http.X-Forwarded-Proto !~ "(?i)https") { set req.http.x-Redir-Url = "https://example.org" +req.url; error 750 req.http.x-Redir-Url; }}sub vcl_error { if (obj.status == 750) { set obj.http.Location = obj.response; set obj.status = 302; return (deliver); }}
  71. 71. sub vcl_recv { if (req.http.Cookie) { set req.http.Cookie =regsuball(req.http.Cookie,"(^|; ) *__utm.=[^;]+;? *","1"); if (req.http.Cookie == "") { remove req.http.Cookie; } }}
  72. 72. Saving the Request http://www.flickr.com/photos/lwr/5014290292
  73. 73. backend app { .host = "192.168.0.1"; .port = "8080";}backend rescue { .host = "1.1.1.1"; .port = "8080";}
  74. 74. sub vcl_fetch{ if (beresp.status == 500) { return (restart); }}sub vcl_recv{ set req.backend = default; if (req.restarts > 0) { set req.backend = rescue; }}
  75. 75. director balance round-robin{ { .backend = web1; } { .backend = web2; }}director balance random{ { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 }}
  76. 76. director balance fallback{ { .backend = web1; } { .backend = web2; }}director balance client{ { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 }}director balance hash{ { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 }}
  77. 77. stale-while-revalidate - rfc5861
  78. 78. sub vcl_fetch{ set beresp.grace = 30m;}sub vcl_recv{ set req.grace = 15s;}
  79. 79. sub vcl_recv{ set req.grace = 15s; if (!req.backend.healthy) { set req.grace = 5m; }}
  80. 80. probe health { .url = "/test_health"; .expected_response = 200; .interval = 5s; .timeout = 1s; .window = 5; .threshold = 3;}backend default{ .host = "127.0.0.1"; .port = "8080"; .probe = health;}
  81. 81. stale-if-error - rfc5861
  82. 82. sub vcl_fetch{ if (beresp.status == 500) { set beresp.saintmode = 10s; return (restart); } set beresp.grace = 30m;}
  83. 83. Cache Invalidation http://www.flickr.com/photos/r80o/5549288
  84. 84. sub vcl_recv{ if (req.request == "PURGE") { purge_url(req.url); error 200 "Purged"; }}
  85. 85. acl purge_acl { "localhost"; "192.168.55.0/24";}sub vcl_recv{ if (req.request == "PURGE") { if (!client.ip ~ purge_acl) { error 405 "Not allowed"; } purge_url(req.url); error 200 "Purged"; }}
  86. 86. varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 "ban.url .*"
  87. 87. ban req.http.host == "example.com" && req.http.url ~ ".png$"
  88. 88. Edge Side Includes ESI
  89. 89. cacheable for 10 minutes cacheable for 5 seconds Lorem  ipsum  dolor  sit  amet,  consectetur   Lorem  ipsum  dolor  sit  amet,  adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   consectetur  adipiscing  elit.   nunc.  Integer  semper  turpis  et  enim   In  vel  nulla  arcu,  vitae   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   cursus  nunc.  Integer   dolor  sit  amet,  consectetur  adipiscing  elit.   semper  turpis  et  enim  Mauris  vehicula  vesFbulum  dictum.  Aenean   porCtor  iaculis.  Nulla   non  velit  tortor.  Nullam  adipiscing   facilisi.  Lorem  ipsum  dolor   malesuada  aliquam.  Mauris  dignissim,  urna   sit  amet,  consectetur  quis  iaculis  tempus,  justo  libero  porCtor  est,   adipiscing  elit.  Mauris   nec  eleifend  est  elit  vitae  ante.  Curabitur   vehicula  vesFbulum  dictum.   interdum  luctus  metus,  in  pulvinar  lectus   Aenean  non  velit  tortor.   rutrum  sit  amet.  Duis  gravida,  metus  in   Nullam  adipiscing   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   malesuada  aliquam.  Mauris   non  volutpat  nulla  sapien  in  elit.  Nulla   dignissim,  urna  quis  iaculis   rutrum  erat  id  neque  suscipit  eu  ultricies   tempus,  justo  libero   odio  sollicitudin.  Aliquam  a  mi  vel  eros   porCtor  est,  nec  eleifend   placerat  hendrerit.  Phasellus  porCtor,   est  elit  vitae  ante.  Curabitur   augue  sit  amet  vulputate  venenaFs,  dui  leo   interdum  luctus  metus. commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  90. 90. ESI… or Edge Side Includeshttp://www.w3.org/TR/esi-lang
  91. 91. t ESI houWit Lorem  ipsum  dolor  sit  amet,  consectetur   Lorem  ipsum  dolor  sit  amet,   adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   consectetur  adipiscing  elit.   nunc.  Integer  semper  turpis  et  enim   In  vel  nulla  arcu,  vitae   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   cursus  nunc.  Integer   dolor  sit  amet,  consectetur  adipiscing  elit.   semper  turpis  et  enim   Mauris  vehicula  vesFbulum  dictum.  Aenean   porCtor  iaculis.  Nulla   non  velit  tortor.  Nullam  adipiscing   facilisi.  Lorem  ipsum  dolor   malesuada  aliquam.  Mauris  dignissim,  urna   sit  amet,  consectetur   quis  iaculis  tempus,  justo  libero  porCtor  est,   adipiscing  elit.  Mauris   nec  eleifend  est  elit  vitae  ante.  Curabitur   vehicula  vesFbulum  dictum.   interdum  luctus  metus,  in  pulvinar  lectus   Aenean  non  velit  tortor.   rutrum  sit  amet.  Duis  gravida,  metus  in   Nullam  adipiscing   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   malesuada  aliquam.  Mauris   non  volutpat  nulla  sapien  in  elit.  Nulla   dignissim,  urna  quis  iaculis   rutrum  erat  id  neque  suscipit  eu  ultricies   tempus,  justo  libero   odio  sollicitudin.  Aliquam  a  mi  vel  eros   porCtor  est,  nec  eleifend   placerat  hendrerit.  Phasellus  porCtor,   est  elit  vitae  ante.  Curabitur   augue  sit  amet  vulputate  venenaFs,  dui  leo   interdum  luctus  metus. commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  92. 92. ESIW ith <esi:include src="..." /> Lorem  ipsum  dolor  sit  amet,  consectetur   adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   nunc.  Integer  semper  turpis  et  enim   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   dolor  sit  amet,  consectetur  adipiscing  elit.   Mauris  vehicula  vesFbulum  dictum.  Aenean   non  velit  tortor.  Nullam  adipiscing   malesuada  aliquam.  Mauris  dignissim,  urna   quis  iaculis  tempus,  justo  libero  porCtor  est,   nec  eleifend  est  elit  vitae  ante.  Curabitur   interdum  luctus  metus,  in  pulvinar  lectus   rutrum  sit  amet.  Duis  gravida,  metus  in   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   non  volutpat  nulla  sapien  in  elit.  Nulla   rutrum  erat  id  neque  suscipit  eu  ultricies   odio  sollicitudin.  Aliquam  a  mi  vel  eros   placerat  hendrerit.  Phasellus  porCtor,   augue  sit  amet  vulputate  venenaFs,  dui  leo   commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  93. 93. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org HTTP/1.1 200 OK C-C: s-maxage=600 Lorem   <esi:include   ipsum   src="hNp.."  /> dolor   Your PHP application Gateway Cache Browser Cache GET /bar HTTP/1.1Browser Host: foo.org HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: s-maxage=5 Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   Lorem  ipsum   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=600 Lor <esi:include />
  94. 94. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Gateway Cache Browser CacheBrowser HTTP/1.1 200 OK HTTP/1.1 200 OK Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=6002 seconds later… Lor <esi:include />
  95. 95. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Gateway Cache Browser Cache GET /bar HTTP/1.1Browser Host: foo.org HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: s-maxage=5 Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   Lorem  ipsum   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=6007 seconds later… Lor <esi:include />
  96. 96. Surrogate-Capability Surrogate-Controlhttp://www.w3.org/TR/edge-arch
  97. 97. Surrogate-Capability: abc="Surrogate/1.0 ESI/1.0"
  98. 98. Surrogate-Control: content="ESI/1.0"
  99. 99. sub vcl_recv{ set req.http.Surrogate-Capability = "abc=ESI/1.0";}sub vcl_fetch{ if (beresp.http.Surrogate-Control ~ "ESI/1.0") { unset beresp.http.Surrogate-Control; unset beresp.http.Cache-Control; set beresp.do_esi = true; }}
  100. 100. http://www.flickr.com/photos/atoach/2118513722
  101. 101. Caching only works for “safe” HTTP methods (like GET & HEAD)
  102. 102. Never change the state of the server when serving a GET request(we are talking about the application’s state of course, you can log, cache, …)
  103. 103. Cache-Control: private
  104. 104. Pages with cookiesare not cached by default
  105. 105. Terminate SSL
  106. 106. 64 bits
  107. 107. Thank You

×