HTTP cache @ PUG Rome 03-29-2011

2,440 views

Published on

A short presentation about HTTP caching at the Rome PHP User Group.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,440
On SlideShare
0
From Embeds
0
Number of Embeds
94
Actions
Shares
0
Downloads
38
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • Ne consegue che non dobbiamo reinventare sempre la ruota.
  • HTTP cache @ PUG Rome 03-29-2011

    1. 1. HTTP cache Alessandro Nadalin March, 29th 2011
    2. 2. The Web is inconsistent
    3. 3. get over it
    4. 4. Why?
    5. 5. Because it scales to billions of users
    6. 6. Because it scales to billions of users WWW data traffic won't be possible without being inconsistent
    7. 7. How does it scales?
    8. 8. Cache
    9. 9. What is caching?
    10. 10. Storing data so that future requests for that data can be served faster ( general purpose )
    11. 11. Process of storing copies of your most accessed resources near to a/some client/s ( the WWW )
    12. 12. Caching is not saving a webpage , or a fragment of it, on the disk, to serve it to the next client
    13. 13. Caching is not saving a webpage , or a fragment of it, on the disk, to serve it to the next client This is a caching mechanism
    14. 14. Disk-persisted or in-memory
    15. 15. Can be distributed
    16. 16. Can be distributed with a NoSQL database
    17. 17. Cache implementation can be really funny
    18. 18. Don't reinvent the wheel
    19. 19. Goals
    20. 20. Goals evolve
    21. 21. Goals evolve loose coupling
    22. 22. Goals Work less evolve loose coupling
    23. 23. Evolve   Because you want your platform to extensible
    24. 24. Evolve   Because you want your platform to extensible   Loose coupling   Because you want it to be easy to integrate with, evolve, plug and mantain
    25. 25. Evolve   Because you want your platform to extensible   Loose coupling   Because you want it to be easy to integrate with, evolve, plug and mantain Work less Because every LoC is bug-prone and our man-day is a hard to scale cost
    26. 26. enters our Hero #1
    27. 29. enters our Hero #2
    28. 31. http://www.lullabot.com/articles/a-beginners-guide-to-caching-data
    29. 32. Goals Work less evolve loose coupling
    30. 33. Goals Work less evolve loose coupling
    31. 34. everything is done for us! :) but....
    32. 35. tmp files, cache tables, procedural crap... mmmmh.... gotta be something better
    33. 36. Frameworks
    34. 38. Cache is used for compiling routes, autoloading, ...
    35. 39. Cache is used for compiling routes, autoloading, ... ...but also for storing the view
    36. 40. Goals Work less evolve loose coupling
    37. 41. Goals Work less evolve loose coupling
    38. 42. at least because we use a framework
    39. 43. but, probably
    40. 44. PHP sucks
    41. 45. Let's call a hero, from the East
    42. 46. on Rails
    43. 48. Goals Work less evolve loose coupling
    44. 49. gosh :-(
    45. 50. hey, what about the latest products?
    46. 51. both Symfony2 and Ruby's Rack  embrace
    47. 52. HTTP
    48. 53. (here comes the nice part)
    49. 54. Local Shared/proxy   Shared/reverse proxy
    50. 55. Local Shared/proxy   Shared/reverse proxy
    51. 57. Local Shared/proxy   Shared/reverse proxy
    52. 59. Local Shared/proxy   Shared/reverse proxy
    53. 61. on the server side
    54. 62. Proxy Reverse proxy http://www.codeproject.com/KB/aspnet/ExploringCaching.aspx
    55. 63. There is something cool about caching softwares.
    56. 64. Free as free beer
    57. 65. ...but the server should take advantage of them ( the boring part were you need to write code )
    58. 66. and here are a few ways to do so, using
    59. 67. and here are a few ways to do so, using expiration
    60. 68. and here are a few ways to do so, using expiration validation
    61. 69. and here are a few ways to do so, using expiration validation invalidation
    62. 70. and here are a few ways to do so, using expiration validation invalidation we will se why
    63. 71. Expiration
    64. 72. GET / HTTP/1.1 Host: www.example.com Expires: 0
    65. 73. GET / HTTP/1.1 Host: www.example.com Expires: 0
    66. 74. GET / HTTP/1.1 Host: www.example.com Expires: Tue, 15 Nov 1994 01:00 GMT
    67. 75. GET / HTTP/1.1 Host: www.example.com Cache-Control: max-age=60, public
    68. 76. GET / HTTP/1.1 Host: www.example.com Cache-Control: max-age=60, public
    69. 77. GET / HTTP/1.1 Host: www.example.com Cache-Control: max-age=60 , public Cacheable for 60 seconds
    70. 78. GET / HTTP/1.1 Host: www.example.com Cache-Control: max-age=60, public Cacheable by both local and shared caches
    71. 79. GET / HTTP/1.1 Host: www.example.com Cache-Control: stale-if-error=600, stale-while-revalidate=600
    72. 80. GET / HTTP/1.1 Host: www.example.com Cache-Control: stale-if-error=600, stale-while-revalidate=600 fault-tolerant
    73. 81. GET / HTTP/1.1 Host: www.example.com Cache-Control: stale-if-error=600, stale-while-revalidate=600 available during downtime
    74. 82. GET / HTTP/1.1 Host: www.example.com Cache-Control: stale-if-error=600, stale-while-revalidate=600 available during revalidation
    75. 83. Validation
    76. 84. GET / HTTP/1.1 Host: www.example.com Etag: 1234
    77. 85. GET / HTTP/1.1 Host: www.example.com Etag: 1234 an identifier for your response
    78. 86. GET / HTTP/1.1 Host: www.example.com If-None-Match: 1234 the browsers asks you if it has been modified Conditional requests
    79. 87. Relax
    80. 88. Calculating an Etag is cheaper than generating a full MVC response
    81. 89. HTTP/1.1 304 Not Modified
    82. 90. GET / HTTP/1.1 Host: www.example.com Last-Modified: Tue, 15 Jan 2011 12:00:00 GMT
    83. 91. GET / HTTP/1.1 Host: www.example.com Last-Modified: Tue, 15 Jan 2011 12:00:00 GMT tell the client about the latest change
    84. 92. GET / HTTP/1.1 Host: www.example.com If-Modified-Since: Tue, 15 Jan 2011 12:00:00 GMT the client asks you if it has been modified since the last time Conditional requests
    85. 93. Relax
    86. 94. Calculating a date is cheaper than retrieving an entire object
    87. 95. HTTP/1.1 304 Not Modified
    88. 96. Invalidation
    89. 97. The web is not meant for invalidating data . Server should not be able to keep clients' state, otherwise they wont scale well. That's why long-polling and endless connections haven't had big success dealing with caching.
    90. 98. but hey, you say
    91. 99. HTTP's cache fails when dealing with really dynamic pages, because consumers will always have to hit the origin server, although a part of the page would be cacheable ( header and footer, for example )
    92. 100. Nope Nope
    93. 101. ESI was built for that http://www.w3.org/TR/esi-lang
    94. 102. and hey, Varnish is a reverse proxy implementing what you need of the ESI specification take 2, pay for 1
    95. 103. So what does HTTP cache is meant to solve?
    96. 104. Less work
    97. 105. because the hard work is delegated to the browser/proxy http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/
    98. 106. evolve
    99. 107. because cache is abstracted from the application
    100. 108. loose coupling
    101. 109. because caching is bound to the protocol, HTTP, not to your implementation ( Sf, RoR, Django )
    102. 110. <ul><li>The presentations lacks on technical stuff </li></ul><ul><li>So here are a few resource for who wants documentation: </li></ul><ul><ul><li>http://tomayko.com/writings/things-caches-do </li></ul></ul><ul><ul><li>http://www.slideshare.net/fabpot/caching-on-the-edge </li></ul></ul><ul><ul><li>http://www.odino.org/301/rest-better-http-cache </li></ul></ul><ul><ul><li>http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html </li></ul></ul>
    103. 111. Deep version of the same talk, about Sf2 cache internals and ESI
    104. 112. May, 12/14 2011 in Verona   Early bid ends on April, 6th
    105. 113. Thanks! Alessandro Nadalin @_odino_ odino.org

    ×