0

Do APC and Memcached cache the same data? I understand that APC caches both files and objects/variables whereas memcached is object-only, but does memcached offer anything that APC doesn't?

I've seen setups where both are used, but that seems to be a waste of RAM unless I'm missing something?

TIA, JD

1 Answer 1

3

On a single server, there's not much point caching the same data in both places. That will use twice the RAM for no real advantage. In this case, it's probably easiest to use APC, because it's one less process to run, and one less interface to learn.

Memcache becomes more useful when you have a whole cluster of servers. Memcache can be queried by multiple servers (and also by multiple processes on the same server). In contrast, data in the APC cache can only be used by PHP on its own server. This makes Memcache more efficient, because you can cache data once and use it on the whole cluster. Memcache itself also can be clustered, so that you can pool the RAM from a bunch of different machines, and use them all as one big cache.

My company uses both Memcache and APC simultaneously. We have a dozen servers running Memcache; these servers cache complex data structures so that we don't have to make database queries all the time. We also use APC to store a little bit of info that's used all the time, like configuration settings. Without APC, we were inundating our Memcache servers with tons of requests for simple data like "Is the app in read-only mode?" Our Memcache servers could handle it, but it's obviously more efficient to keep that information around in local memory.

1
  • 1
    Also, APC caches the actual PHP code that is executing. This is a major bonus as it means the code doesn't have to be "recompiled" for each request.
    – devicenull
    Feb 15, 2011 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .