Memcache
Making applications scale with caching
David Rasch
david@davidrasch.com
May 2007 TriPUG and MySQL Meeting sponsored by Capital TechSearch
What's Memcache?
- Written by people at Danga (makers of LiveJournal
- Key/value pair storage
Architecture
- Client - installed as a library/extension to your dynamic content engine (we'll be using an extension to PHP)
- Server - small server with a slab of memory for storing stuffs
Setup - Client
Easy using Ubuntu Feisty 07.04
# aptitude install php5-memcache
# /etc/init.d/apache2 restart
Setup - Server
Also easy using Ubuntu Feisty 07.04
# aptitude install memcached
In action: Let's make a 'blog'
- Create Database
- Create a Table
- Insert some Data
- Write the Blog
Peforms Great!
MySQL Query cache!
What if we track how many times each post was viewed?
(see 2-uncached/ and 3-refactored/)
Now it's slow :-(
Let's make it cache! (see 4-cached/ directory)
Included code
- 0-slides/ - looks like you found this
- 1-original/ - original 'blog'
- 2-uncached/ - implemented views, no caching
- 3-refactored/ - refactored a bit ready for caching
- 4-cached/ - caching implemented
Included code
- db.sql - sql for each step
- blog.php - main blog view, shows 10 most recent posts
- addpost.php - for adding a post to the blog
- blog_common.inc.php - common blog 'service' and code
- createposts.php - only in original directory; for inserting substantial test data
- perf.txt - performance data