Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Caching - A Primer
Ash Christopher
April 15, 2012
6
2.5k
Caching - A Primer
Ash Christopher
April 15, 2012
Tweet
Share
More Decks by Ash Christopher
See All by Ash Christopher
ashchristopher
10
1.7k
ashchristopher
1
84
ashchristopher
9
1.7k
ashchristopher
5
2.1k
ashchristopher
18
2.8k
Featured
See All Featured
addyosmani
311
21k
bkeepers
321
53k
sstephenson
145
12k
hursman
107
9.2k
maltzj
501
36k
deanohume
295
28k
cherdarchuk
71
260k
rmw
11
810
destraynor
146
19k
colly
66
3k
jcasabona
8
550
jonrohan
1022
380k
Transcript
Caching and Django A Primer @ashchristopher
What is a Cache?
Temporary storage of non-complex data
Provides very fast lookups
Django supports simple caching
Django includes support for a number of cache backends out-of-the-box
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
Easy to make your own cache backend
Extend core.cache.backends.base.BaseCache
Simple caching follows the same pattern
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.
Your system works even if your cache is offline
Some cool projects/apps to help you with it
Django Middleware (per-site and per-view)
Cache Machine
Johnny-Cache
None
Low-level Caching (doing it by hand)
Caching is simple...
... except when it isn’t!
Cache invalidation is hard
Cache invalidation is especially hard at scale
What happens when an expensive operation falls out of cache?
Thundering Herd
Fundamental flaw?
I think so!
Caching doesn’t mean what it used to mean
What you want is probably not caching
Denormalized Data
Actively set new data instead of letting things fall out
of cache
Nothing falls out of cache
Set your data via asynchronous processes
None
No Silver Bullet
Optimizing read speed by adding redundant data
Persistent storage
NoSQL
There is a problem with denormalized data at scale
Denormalized data becomes a requirement
What problem?
Embrace denormalized data
@ashchristopher ash.christopher@gmail.com