Alternative PHP cache (APC)

Stores ::: cachestore_apc
Maintained by Sam HemelrykSam Hemelryk
The alternative PHP cache (APC) is an opcode cache for PHP that provides a persistent application data store cache to PHP applications. This plugin allows the use of that APC data store as a Moodle cache store. In turn allowing you to use APC within Moodle.
Latest release:
61 sites
5 fans
Current versions available: 1

Information and advice on using APC within Moodle

APC provides a shared application cache that is usually very limited in size but provides excellent performance. It doesn't provide the ability to configure multiple instances of itself and as such within Moodle you are only able to create a single APC cache store instance. Because of its incredible performance but very limited size it is strongly suggested that you map only small, crucial caches to the APC store.

Another important thing to understand about the APC store is that it provides no garbage cleaning, or storage reclamation facilities. As such cache data will persist there until APC is restarted or the store is purged. On top of that once the store is full requests to store information within the cache fail until there is once more sufficient space. Because of this it is recommended that you regularly purge or restart APC. Also recommended is to map a secondary application cache instance to any definition with the APC mapped. This ensures that if it does indeed full up that an alternative cache is available.

Installation of APC

It is recommended that you read through the APC documentation before beginning with this plugin. The above documentation recommends installing the PECL APC extension that can be found at contains information on installing PECL extensions.

Its also worth noting for this those using Linux that there is usually a php5-apc package that can be installed very easily. If you have installed PHP under Linux through a package manager then this will be by far the easiest way to proceed.

Once installed ensure you restart your web server before proceeding.

Installation within Moodle

Browse to your site and log in as an administrator. Moodle should detect that a new plugin has been added and will proceed to prompt you through an upgrade process to install it. The installation of this plugin is very minimal. Once installed you will need to need to create an APC cache store instance within the Moodle administration interfaces.

Making use of APC within Moodle

Installing this plugin makes APC available to use within Moodle however it does not put it into use. The first thing you will need to do is create an APC cache store instance. This is done through the Cache configuration interface.

  1. Log in as an Administrator.
  2. In the settings block browse to Site Administration > Plugins > Caching > Configuration.
  3. Once the page loads locate the APC row within the Installed cache stores table.
  4. You should see an "Add instance" link within that row. If not then the APC extension has not being installed correctly.
  5. Click "Add instance".
  6. Give the new instance a name and click "Save changes". You should be directed back to the configuration page.
  7. Locate the Configured cache store instances table and ensure there is now a row for you APC instance and that it has a green tick in the ready column.

Once done you have an APC instance that is ready to be used. The next step is to map definitions to make use of the APC instance.

Locate the known cache definitions table. This table lists the caches being used within Moodle at the moment. For each cache you should be able to Edit mappings. Find a cache that you would like to map to the APC instance and click Edit mappings. One the next screen proceed to select your APC instance as the primary cache and save changes. Back in the known cache definitions table you should now see your APC instance listed under the store mappings for the cache you had selected. You can proceed to map as many or as few cache definitions to the APC instance as you see fit.

That is it! you are now using APC within Moodle.

Bugs, feature requests, help, and further information

For bug and feature requests please create issues at For help please visit the Hardware and performance forum. For more information please visit


Sam Hemelryk
Sam Hemelryk (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Sam Hemelryk
    Mon, Apr 15, 2013, 6:40 AM
    Hi Roland,

    The data store provided by APC is extremely fast, however it is usually limited in size (of course you can configure this). If the data store becomes full requests to set any new data fail.
    This ties into your questions.
    In regards to selecting cache definitions I would suggest selecting a couple of really core definitions to begin with, definitions like lang strings and config are used on every single page so are probably a good couple of start with.
    Once configured you can monitor APC checking up on how much storage is being used. Ensure there is always storage available. From there you should be able to either tweak the data store size of APC, or add additional definitions to it.

    As for primary and final store, I'd highly recommend not selecting APC for both. The idea behind stacking the stores is that should your primary store not be available (if it were full for example) then the secondary store would be available for use.
    It's not ideal to have things fall back to a secondary cache obviously, however it beats having to generate data for every request on top of trying to get it from a cache.

    I hope that answers your questions.

    Many thanks
  • Sam Hemelryk
    Tue, Apr 16, 2013, 5:06 AM
    MDL-39117 has been created to decide whether this plugin should be included as part of Moodle core.
    Please vote for the issue if you would like to see it become part of Moodle, or comment if you have thoughts to share.
  • Wed, Apr 17, 2013, 11:09 PM
    Many thanks for the above info, Sam - v. useful and much appreciated. Also, this should definitely be part of the core, imo - so I'll make sure to vote accordingly. Thanks again.
  • Tue, Jun 11, 2013, 11:38 PM
    Hi Sam,

    Can you confirm which directory we copy the plugin into, I assumed /mod but I get an error trying to install on 2.4
    Plugin "mod_apc" is defective or outdated, can not continue, sorry.

  • MD shot of me from his iphone4
    Wed, Jun 12, 2013, 10:08 AM
    /cache/stores/ - normally can be inferred from the frankenstyle too (here its 'cachestore_*')
  • Thu, Aug 8, 2013, 4:39 AM
    On Debian, the php-apc package is installed with the "apc.cache_by_default" enabled. Using the apc.php script I can see APC caching things like lib/moodlelib.php, even though the module isn't installed. So what's the advantage of using this plugin within Moodle? Thanks.
  • Sam Hemelryk
    Thu, Aug 8, 2013, 9:38 AM
    Hi Jérôme, APC will cache files by default. This plugin uses the APC data store to cache shared data. By default files are written to FS to enable sharing cached data and APC tends to be much faster than that.
  • Sun, Aug 25, 2013, 12:40 AM
    Hello, I am encountering a PHP warning while executing purge_caches.php. This is the error:

    PHP Warning: apc_cache_info(): No APC info available. Perhaps APC is not enabled? Check apc.enabled in your ini file in /var/www/elo/html/cache/stores/apc/lib.php on line 257

    What am I doing wrong?
  • Ying Yang
    Tue, May 13, 2014, 3:01 PM
    After upgrading to Moodle 2.6.3 I am seeing pages of warning messages relating to APC Store:
    Notice: Undefined index: info in /srv/htdocs/cache/stores/apc/lib.php on line 259

    Warning: apc_delete(): apc_delete() expects a string, array of strings, or APCIterator instance. in /srv/htdocs/cache/stores/apc/lib.php on line 259
  • Sam Hemelryk
    Wed, May 14, 2014, 4:48 AM
    Hi James, I've posted an updated version here now.
    Thanks for the heads up, I had fixed this locally but not shared it here - oops.
  • Thu, Jun 5, 2014, 12:15 AM
    When I add an instance and save changes, the new store instance is not showing up in the table. Next to the APC plugin listed in the Installed cache stores table, it shows 0 under Stores. Any ideas?
  • Tue, Sep 23, 2014, 5:30 AM
    Hello, I've been using APC in Moodle, both as opcache and MUC store successfully for a while. Now that Moodle has settled on discouraging the use of APC in favor of PHP OPcache, I'd like to know a bit more about how this development relates to this plugin. More specifically, is it possible to run both APC and OPcache, using APC only as a Moodle cache store and OPcache as opcode cache? Does Moodle allow the use of OPcache as a cache store? Will this plugin continue to be maintained? Thanks.
  • One poor developer...
    Tue, Dec 23, 2014, 11:17 PM
    Hi Jérôme,

    think that, in order to use OPCache (really recommended), instead of using the whole APC, you can just install APCu (the caching part of APC). It provides PHP API compatibility with the old APC, so should work as a simple replacement. (Disclosure: I've not tested APCu, just sharing it's supposed to be the user cache alternative for people moving to OPCache from APC).

    Some links:
  • Ying Yang
    Mon, Feb 9, 2015, 11:28 AM
    Please see the compatibility issue on GitHub
    The most recent commits remove compatibility with everything <2.9Dev, so it no longer works with 2.6, 2.7, or 2.8.
  • Mon, Sep 25, 2017, 7:06 PM
    I had tried to implement it, but it didn't work for me.
1 2
Please login to post comments