Your SlideShare is downloading. ×
Caching Strategies
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Caching Strategies

7,888
views

Published on

A common request sent from your web browser to a web server goes quite a long way and it can take a great deal of time until the data your browser can display are fetched back. I will talk about …

A common request sent from your web browser to a web server goes quite a long way and it can take a great deal of time until the data your browser can display are fetched back. I will talk about making this great deal of time significantly less great by caching things on different levels, starting with client-side caching for faster display and minimizing transferred data, storing results of already performed operations and computations and finishing with lowering the load of database servers by caching result sets. Cache expiration and invalidation is the hardest part so I will cover that too. Presentation will be focused mainly on PHP, but most of the principles are quite general work elsewhere too.

Published in: Technology

1 Comment
17 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,888
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
172
Comments
1
Likes
17
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Q: Kdo víte, co je to cache? ME: cache je rychlé úložiště, kam s ukládají data z pomalého úložiště Q: kdo si myslí, že jsem to řekl špatně? Me: popovídáme si potom Q: kdo používáte nějakou cache? Me: všichni
  • Ukázkový model
  • Co znamená cache, jak se chová klient, v nejlepším případě neodejde žádný požadavel na server
  • Když odejde, server vrátí v odpovědi tyto hlavičky
  • Hlavičky pro podmíněné dotazy mají obrácené varianty
  • Má spoustu parametrů, tohle jsou nejzajímavější, zbytek by vydal na druhou přednášku
  • V ideálním případě odpovídá cache, ne půvvodní server
  • Víc se toho říct nedá, to je taky na samostatnou přednášku
  • ...Což není tak jednoduchý, protože
  • Největší teoretik v čechách napsal článek, návrh, jak to celý zautomatizovat, problém je ten, že existuje snad jen jeden člověk, který to dokáže prakticky napsat.
  • Transcript

    • 1. Caching Strategies Michal Špaček, Skype; WebExpo 2011 , Prague @spazef0rze, www.michalspacek.cz
    • 2. What the... Cache ? HDD cache, CPU cache, DNS cache, web cache, geocache
    • 3. What the... Cache ? HDD cache, CPU cache, DNS cache, web cache , geocache
    • 4. CLIENT (BROWSER) WEB SERVER DATABASE SERVER
    • 5. HTTP level caching
    • 6. Client local disk/memory cache CLIENT (BROWSER) WEB SERVER
    • 7. Response headers: Expires Last-Modified ETag Cache-Control Pragma CLIENT (BROWSER) WEB SERVER
    • 8. Expires: HTTP-date Expires: Sat, 24 Sep 2011 12:00:00 GMT < Expires CLIENT (BROWSER)
    • 9. Expires: HTTP-date Expires: Sat, 24 Sep 2011 12:00:00 GMT > Expires CLIENT (BROWSER) WEB SERVER
    • 10. Last-Modified: HTTP-date Following request: If-Modified-Since: HTTP-date
    • 11. Last-Modified: HTTP-date Following request: If-Modified-Since: HTTP-date Response: Entity modified: HTTP 200 OK Not modified: HTTP 304 Not Modified
    • 12. Last-Modified: HTTP-date Saves bandwidth!
    • 13. ETag: quoted-string Following request: If-None-Match: quoted-string
    • 14. ETag: quoted-string Following request: If-None-Match: quoted-string Response: No match : HTTP 200 OK A match: HTTP 304 Not Modified
    • 15. Saves bandwidth, too! ETag: quoted-string
    • 16. If-Modified-Since If-Unmodified-Since If-None-Match If-Match
    • 17. ETag × Last-Modified hash (GUID) × HTTP-date (seconds)
    • 18. ETag × Last-Modified hash (GUID) × HTTP-date (seconds) weak+strong validation × strong
    • 19. ETag × Last-Modified hash (GUID) × HTTP-date (seconds) weak+strong validation × strong needs content × needs date
    • 20. Request+Response header Cache-Control: whatever
    • 21. Request+Response header whatever = max-age , no-cache , public , must-revalidate (response only), ... Cache-Control: whatever
    • 22. Pragma: no-cache Request+Response header
    • 23. Pragma: no-cache Request+Response header Request: HTTP 1.0 variant of Cache-Control: no-cache
    • 24. Pragma: no-cache Request+Response header Request: HTTP 1.0 variant of Cache-Control: no-cache Response: meaning undefined, wtf
    • 25. Proxy cache CLIENT (BROWSER) WEB SERVER
    • 26. Proxy cache CLIENT (BROWSER) WEB SERVER
    • 27. Application level caching
    • 28. Configuration Does not change often
    • 29. Configuration Does not change often Parse (files)/read (from db) and store to APC
    • 30. APC: The Alternative PHP Cache PHP extension Data store (also opcode cache)
    • 31. APC: The Alternative PHP Cache Data persist between requests
    • 32. APC: The Alternative PHP Cache Data persist between requests … until deleted or cache cleared or server restarted
    • 33. Database connection cache Persistent connections (don't work) Connection pooler
    • 34. Database query cache Some systems have query cache
    • 35. Database query cache Some systems have query cache Some don't
    • 36. Result set cache Some data don't change
    • 37. Result set cache Some data don't change Fetch and store to memcached
    • 38. Memcached Client-server architecture Key-value in memory store for strings and objects
    • 39. Problems with caching
    • 40. Data change sometimes but not often enough Employee list of a company
    • 41. Data change sometimes but not often enough Employee list of a company Invalidate cache when adding or removing employees
    • 42. Data change sometimes and delay is okay Translations from database
    • 43. Data change sometimes and delay is okay Translations from database Introduce cache lifetime
    • 44. Moar cache keys for the same data Sorted employee list (asc, desc)
    • 45. Moar cache keys for the same data Sorted employee list (asc, desc) Cache groups
    • 46. Cache groups Keys: list-sorted-asc, list-sorted-desc
    • 47. Cache groups Keys: list-sorted-asc, list-sorted-desc Group „list“: list-sorted-asc, list-sorted-desc, list-unsorted
    • 48. Cache groups Keys: list-sorted-asc, list-sorted-desc Group „list“: list-sorted-asc, list-sorted-desc, list-unsorted Delete group „list“ when adding/removing
    • 49. Cache wherever and whatever
    • 50. … but delete your whatever when needed
    • 51. Caching is magic
    • 52. Caching is magic but not automagic
    • 53. Caching is magic but not automagic until now
    • 54. www.phpguru.cz/kaskadova-cache
        2010 © Skype – As seen on TV
        Slide
    • 55. Practical implementation, anyone ?
        2010 © Skype – As seen on TV
        Slide
    • 56.
        Thanks for listening Michal Špaček, @spazef0rze BTW, love caching? skypecareers.com!