Stores: XCache

Maintained by Sam Hemelryk Sam Hemelryk
XCache is a PHP opcode cacher designed to accelerate the performance of PHP execution. One of the features it provides is a variable data store that can be used within PHP code to persist variables between requests. This plugin is an XCache cache store designed to utilise that variable data store and allow Moodle to make better use of XCache.
28 sites
3 fans

Information and advice on using XCache within Moodle

XCache 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. Moodle allows the admin to create several XCache instances however the prefix for each must be unique as they will all exist within the single XCache variable data store. Because of its incredible performance but very limited size it is strongly suggested that you map only small, crucial caches to the XCache store.

Also recommended is to map a secondary application cache instance to any definition with the XCache mapped. This ensures that should the XCache data store fill up there will be an alternative cache available.

Installation of XCache

For those running an Linux distro and having installed PHP through a package manager I would recommend first checking your package manager to see if an XCache package is provided. If so I would certainly recommend installing through the package manager as it is by far the easiest route. Through Ubuntu/Debian this can be achieved using the following command:

sudo apt-get install php5-xcache

It is recommended to follow the installation instructions that XCache provide. You can download XCache from I recommend using the latest stable version. Installation depends upon whether you are installing from source, or installing a prebuilt binary package. Documentation on both methods can be found at (Look for the Install from ... links on the right)

Configuring XCache for use

Detailed information about the ini settings can be found at There are a couple that we recommend understanding as they are vital to the use of this plugin.

# Controls the size of the variable cache available through XCache.
# It must be set > 0 in order for the this plugin to be usable.
xcache.var_size = 64m

# Sets a default TTL for cached variables.
# Highly recommend setting this as it ensures you don't end up with
# a cache full of stale data.
xcache.var_ttl = 3600

# Sets the garbage collection interval. Essential for keeping the
# cache free of stale data.
xcache.var_gc_interval = 300

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 XCache cache store instance within the Moodle administration interfaces.

Making use of XCache within Moodle

Installing this plugin makes XCache available to use within Moodle however it does not put it into use. The first thing you will need to do is create an XCache 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 XCache row within the Installed cache stores table.
  4. You should see an "Add instance" link within that row. If not then the XCache 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 XCache instance and that it has a green tick in the ready column.

Once done you have an XCache instance that is ready to be used. The next step is to map definitions to make use of the XCache 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 XCache instance and click Edit mappings. One the next screen proceed to select your XCache instance as the primary cache and save changes. Back in the known cache definitions table you should now see your XCache 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 XCache instance as you see fit.

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

Bugs, feature requests, help, and further information

For bug and feature requests please create issues at For help please visit the forums. 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
  • David
    Fri, 12 Apr 2013, 4:22 PM
    You sir, are my personal hero! thank you for this! Combined with memcached in 2.4 (which was silently added) I think we can make Moodle perform like any other application
  • Sam Hemelryk
    Mon, 15 Apr 2013, 6:43 AM
    Hopefully so, thanks for using this plugin David!
  • Picture of Rogier Dikkes
    Mon, 15 Apr 2013, 8:02 PM
    Hi Sam,

    Will this eventually become part of the core like the MUC for memcached?
  • Sam Hemelryk
    Tue, 16 Apr 2013, 5:10 AM
    Hi Rogier,
    The release of Moodle 2.5 is just around the corner now and no new features will be accepted.
    After the release I will discuss the possibility of including this plugin within Moodle core with HQ.
    All going well I'd like to see this included within Moodle core.
    Assuming people agree to include it it would be present in Moodle 2.6 onwards. For earlier versions of Moodle people would need to install the plugin from here.

    Many thanks
  • Picture of Lael ...
    Fri, 24 May 2013, 8:34 AM
    Given this is a variable cache I assume it can't be used for files? What mappings would you recommend to use for this cache?

  • Sam Hemelryk
    Fri, 24 May 2013, 9:41 AM
    Hi Lael,

    You're correct in assuming that this cannot be used for files.

    XCache is very much like APC. In fact someone asked me a similar question on that plugin not too long ago.
    The data store provided by XCache is ultra fast with virtually no overhead, however it is usually limited in size (of course you can configure this).
    It's important to know that if the data store becomes full requests to set any new data fail and performance will rapidly degrade.
    When 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.
    The advantage with these two as well is that you know that they are of constant size and it will be easy to test and monitor storage capacity
    Once configured you can monitor XCache 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 and/or map additional definitions to it.
    If you find something that really works well for you perhaps you could consider sharing it here to that others may see it.

    Hope that helps
  • Picture of Andrew Chapman
    Thu, 18 Jul 2013, 2:56 PM
    Which of the "Known cache definitions" should be mapped to xcache? I tried adding a variety of application mode settings, but some of them just caused Apache to die (for example, Database meta information, and Course Group Information). There is no indication from within Moodle as to which modes are suitable. A list here would be quite useful for Moodle 2.5. Thank you.
  • Picture of Jordi Fontseca
    Fri, 19 Sep 2014, 5:22 PM
    Hi, thanks for sharing this plugin. Will it work with Moodle 2.7? Has anyone tested it?
  • Picture of Uriy Dyachek
    Wed, 18 Apr 2018, 4:16 AM
    On my games projects search is already realized with the help of this PHP opcode. It's important to know that if the data store becomes full requests to set any new data fail and performance will rapidly degrade.
    When 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.
Please login to post comments