Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Caching - A Primer
Search
Ash Christopher
April 15, 2012
6
2.6k
Caching - A Primer
Ash Christopher
April 15, 2012
Tweet
Share
More Decks by Ash Christopher
See All by Ash Christopher
Database Sharding with Django - DjangoCon 2013
ashchristopher
10
1.9k
Testing at Scale
ashchristopher
1
110
Horizontally Scaling Your Database with Django - PyCon.ca (2012)
ashchristopher
10
1.8k
Scaling with Django
ashchristopher
5
2.3k
Django - Don't Do This!
ashchristopher
18
3.1k
Featured
See All Featured
Practical Orchestrator
shlominoach
180
9.7k
How To Stay Up To Date on Web Technology
chriscoyier
781
250k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
242
12k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
118
38k
Robots, Beer and Maslow
schacon
PRO
154
7.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
10
4.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
657
120k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
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
[email protected]