A while back I did Cache Performance Comparison for LAMP Stack.
Looking at this data you can see memcached is about 5 times as slow as APC, and this is with tests done on localhost – with network difference is going to be larger, even with fastest network. Such latency can add up especially if you’re, being lazy “P” Developer, request objects from cache one by one rather than fetching all items you need for the page at once (not to mention this is not always possible).
So I thought if there is any way to use both of them at once benefiting from strong sides of each of them.
APC Cache (Eaccelerator and other similar caches) is Fast but it is not distributed so you’re wasting cache and reducing possible hit rate by caching things locally if you have many web servers. MemcacheD is relatively slow but distributed and so you do not waste memory by caching same item in a few places, it is also faster to warmup as you need only one access to bring item into the cache, not access for each of web servers.
The good thing however is you do not have to select one or another, you can use both at the same time. APC will be great for caching small but frequently accessed things which are not taking too much memory. For example if you store list of states in the database you can cache it this way. For NNSEEK we can use it to cache list of languages, top groups and much of semi-static modules shown on group directory pages. Memcached is good for caching things which take large amount of space combined and which you only need to fetch few per page. For example search results may be good candidate (assuming we want to cache them and want to cache them in memory).
Sometimes I add third level of caching – disk based (database or file based) to cache large size or persistent objects which have long time and which would be too bad to generate each time. This especially applies to data which comes from network – Web services results etc.
What do you think ?
Resources
RELATED POSTS