Caching: A Guided Tour - 10/12/2010
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
627
On Slideshare
625
From Embeds
2
Number of Embeds
2

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 2

http://www.linkedin.com 1
https://www.linkedin.com 1

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















  • Straight TTL on the cache entry will not help
    You need to store the data with a modTime field, and check that field on pullback of the data.







  • Code Example

Transcript

  • 1. Caching: A Guided Tour Jason Ragsdale - DPUG 10/12/2010
  • 2. Overview • When to cache? • What to cache? • Page, Fragment and Data • File system, Database and In-Memory • Managing your TTL’s • Clearing / Invalidation
  • 3. When to cache? • When you are accessing: • Read only / mostly static data • High latency external services • Repeated page segments
  • 4. When to cache? • Short answer : Always
  • 5. What to cache? • Database data • Web service data • Dynamically generated content
  • 6. Page caching • Caching the content of a whole page
  • 7. Fragment caching • Caching a portion of a page
  • 8. Data caching • Storing of return data from a service • Database • Web services
  • 9. File system • PRO: • Fast (depending on hardware) • Persistent data • Can operate on data via cron jobs
  • 10. File system • CON: • Slow (depending on hardware) • Open file limits of OS • Max inode limits of OS/FS • File lock issues on writes • Does not scale well
  • 11. Database • PRO: • Fast - Can rely on DB caching • Flexable - Can scale • Persistent data • Can operate on data via cron jobs
  • 12. Database • CON: • Relying on the DB being available • Caching DB data back into the DB • Flat file DB’s can have file lock issues
  • 13. Database - Clarification • When speaking of DB caching we are talking about caching of content into a table not the caching mechanisms of the DB itself.
  • 14. In-Memory • PRO: • Fast: Local memory access is cheap • Distributed access is cheap (network) • Flexible - can scale
  • 15. In-Memory • CON: • Non-Persistent data (normally) • No security built in
  • 16. Managing your TTL’s • Same content called from multiple API’s • API 1 want’s data that is no older than 1 hour • API 2 want’s data that is no older than 24 hours
  • 17. Clearing your cache • Data is no longer valid • Clear to force a new call to the fresh data
  • 18. Invalidating your cache • What if you do not know all possible keys? • Item ‘123456’ • ‘123456_methodname_param’ • You do not know all ‘methodnames’ or ‘params’
  • 19. Invalidating your cache • Create a “key” that you can invalidate • Create a cache entry ‘ver_123456’ with the value of the current unixtime • ‘123456_unixtime_methodname_param’ • Now you can invalidate an item just by changing the value of the ‘ver’ record, TTL will take care old ver’s
  • 20. <?php time • pecl/apc • pecl/memcache • pecl/memcached (huh? two of them?)
  • 21. APC • Built in cache for php (may have to compile it) • Provides opcode caching • Provides ability to cache data
  • 22. APC (the dark side) • Cache race/locking/overwriting issues
  • 23. memcached • Fast • Easy to set up • Easy to configure for distributed caching
  • 24. cache_object • __call - Where the magic happens
  • 25. Q&A