Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Memcached FTW
1. memcached FTW!
Because performance does matter
BarCamp Brighton 2 - March 16 2008
Marco van Hylckama Vlieg
marco@i-marco.nl
http://www.i-marco.nl/weblog/
2. memcached
• memcached is used by very large, high
profile websites such as Livejournal,
Wikipedia and Facebook
• General purpose, scalable caching solution
• Extremely fast
• Extremely easy to use
3. Universal
• memcached can be used with just about
any programming language
• Runs on almost any box
• Multiple boxes can be deployed
• Can be used with PHP, Python, Perl, Java,
C#, Ruby, ...
4. How does it work?
• Store anything that can be serialised
• Store with unique key
• Fetch back with this unique key
• Expire time can be set
5. Usage pattern
• Store items with key and expire time
• Request item :
• found? return it!
• not found? produce item and store in
cache
• If needed, create own expiration
mechanism
6. Limitations
• Can’t dump contents of the cache
• Cache is not persistent
• Not redundant
• No security
• Max 1MB - 42 bytes cached object size (can
be increased at compile time)
7. What to cache?
• SQL resultsets
• Whole pages
• XSLT Transformation results
• Generated HTML fragments
• Images (thumbnails)
• Anything ‘expensive’
8. PHP and memcache
• memcached daemon
• PHP memcache PECL extension (not
installed by default)
• procedural and OO interfaces available