I'm trying to understand the difference between Memcached and APC and why people talk about using one or the other or both. I can't understand why you wouldn't use both because I thought they had completely different roles. Here's my understanding:
APC
This caches chunks of PHP code and stores it in RAM. Then when you need to run that same piece of code again it's already cached and runs from memory lightning fast.
In my particular case of running PHP-FPM, this would reduce the load on that.
Memcached
(I'll ignore the difference between the two php modules and treat them as the same thing for this purpose)
This caches DB objects and stores them in RAM. Then when drupal needs to call the same database object all the information is sitting there and it doesn't need to go to the database.
In my particular case of running MySQL, this would reduce the load on that.
Drupal Cache Bins
There are a bunch of questions on Drupal Stack Exchange about caching and cache bins both which mention APC & memcached:
- In Where is the best place for cache bins, Memcache is recommended because of stability issues with APC.
- In Is there any gain using Memcached module when APC is running good..., it's said the choice comes down to personal preference.
- In Using Drupal 7 with APC, Varnish and Memcache... it talks about combining both of them.
So several of the really informative questions in this area recommend just using Memcached and a couple other ones say there's not a huge difference to introducing both.
But I don't understand how this works. Aren't they caching completely different things?
Suppose I have a view which is used a lot. Isn't memcached caching the DB objects that are shown in the view and APC is caching the module code which calls them?
Is the difference that you can only use one cache for each Drupal cache bin, so you can either choose to cache DB objects or PHP code and in practice most Drupal cache bins have either little performance difference between the two or are too large to cache all the PHP so caching DB objects is the only reasonable option?
(And thus why most people suggest memcache as the default cache bin option i.e. $conf['cache_default_class'] = 'MemCacheDrupal';
)