Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Caching - A Primer

0ba94480bf4840a6957fa83303be919e?s=47 Ash Christopher
April 15, 2012
2.5k

Caching - A Primer

0ba94480bf4840a6957fa83303be919e?s=128

Ash Christopher

April 15, 2012
Tweet

Transcript

  1. Caching and Django A Primer @ashchristopher

  2. What is a Cache?

  3. Temporary storage of non-complex data

  4. Provides very fast lookups

  5. Django supports simple caching

  6. Django includes support for a number of cache backends out-of-the-box

  7. Memcache cluster of Memcache servers Database cache uses database table

    for cache Filesystem cache file on the local filesystem Local memory cache only good for local development
  8. Easy to make your own cache backend

  9. Extend core.cache.backends.base.BaseCache

  10. Simple caching follows the same pattern

  11. 1. Check the cache for data and if found, return

    it 2. If data is not in cache - get data from the database, put data in cache then return the data 3. Invalidate cache on data change.
  12. Your system works even if your cache is offline

  13. Some cool projects/apps to help you with it

  14. Django Middleware (per-site and per-view)

  15. Cache Machine

  16. Johnny-Cache

  17. None
  18. Low-level Caching (doing it by hand)

  19. Caching is simple...

  20. ... except when it isn’t!

  21. Cache invalidation is hard

  22. Cache invalidation is especially hard at scale

  23. What happens when an expensive operation falls out of cache?

  24. Thundering Herd

  25. Fundamental flaw?

  26. I think so!

  27. Caching doesn’t mean what it used to mean

  28. What you want is probably not caching

  29. Denormalized Data

  30. Actively set new data instead of letting things fall out

    of cache
  31. Nothing falls out of cache

  32. Set your data via asynchronous processes

  33. None
  34. No Silver Bullet

  35. Optimizing read speed by adding redundant data

  36. Persistent storage

  37. NoSQL

  38. There is a problem with denormalized data at scale

  39. Denormalized data becomes a requirement

  40. What problem?

  41. Embrace denormalized data

  42. @ashchristopher ash.christopher@gmail.com