7

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:

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';)

  • They're not comparable - APC is an opcode cache (caches results of function calls to speed your code execution up). Memcache, or redis, or whatever in-memory data-store you want to substitute in here, is used as a cache for your site's data. Apples and oranges really. As with any technology, "which should I use?" can only be answered by you, after you've benchmarked their usage on your server with your app and your expected load. See stackoverflow.com/questions/815041/… for general advice on these two – Clive Jun 11 '14 at 12:42
  • 1
    BTW the previous comment is grossly over-simplified (APC can be used as a data-store cache for example, it just generally isn't). I'd recommend reading as much as you can about both types of cache to understand if they're useful for you – Clive Jun 11 '14 at 12:46
  • I was just trying to understand why in a lot of the questions people talk about the decision between APC & memcached. If they're both completely different why wouldn't they both have a place on the same Drupal project to cover their different strengths. Presumably if you set the same cache bin to be covered by APC as opposed to memcached you're getting a completely different cache? (And depending on your site usage and structure one will be better for you) – Dominic Woodman Jun 11 '14 at 12:50
  • 1
    @DominicWoodman The APC module for Drupal doesn't do the op-code caching. It is an alternate cache-back end that uses the APC user-cache. – mpdonadio Jun 11 '14 at 13:04
  • I also think this is a dup. – mpdonadio Jun 11 '14 at 13:04
2

APCu
Does not share the cache with other servers but is faster.

Memcached
Can be shared with other servers and is slower.

If you have 2 or more web servers (apache/nginx) for the same Drupal site you'll want Memcached. If you are running on a single machine then APCu will be the quickest. You'll want OPcache turned on no matter what.

LCache is a module designed to fix the issues with using APCu in a 2 or more web server environment.

0

To find out the major difference between APC and memcache. How to install apc and memcache. You can refer this post. http://www.phpwala.com/php/difference-between-apc-and-memcache-php/2016/02

Really helpful. Thanks

  • 3
    Please don't post link-only answers, as the value of the answer is gone when the link dies. Can you include some quotes of the article in your answer so the bigger picture is also readable here? – Neograph734 Feb 27 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.