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

Like this? Share it with your network

Share

Caching: A Guided Tour - 10/12/2010

on

  • 610 views

 

Statistics

Views

Total Views
610
Views on SlideShare
608
Embed Views
2

Actions

Likes
0
Downloads
1
Comments
0

2 Embeds 2

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

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Straight TTL on the cache entry will not help <br /> You need to store the data with a modTime field, and check that field on pullback of the data. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Code Example <br />
  • <br />

Caching: A Guided Tour - 10/12/2010 Presentation 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