Select Moodle version:

Stores: XCache

cachestore_xcache
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.
Maintained by: Sam@moodle Sam Hemelryk
for Moodle
2.4, 2.5

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 http://xcache.lighttpd.net/wiki/ReleaseArchive. 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 http://xcache.lighttpd.net/wiki/DocToc (Look for the Install from ... links on the right)

Configuring XCache for use

Detailed information about the ini settings can be found at http://xcache.lighttpd.net/wiki/XcacheIni. 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 tracker.moodle.org. For help please visit the moodle.org forums. For more information please visit https://moodle.org/plugins/view.php?plugin=cachestore_xcache

Contributors

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

Comments RSS

Show comments
  • Picture of David Bezemer
    Fri, Apr 12, 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@moodle
    Mon, Apr 15, 2013, 6:43 AM
    Hopefully so, thanks for using this plugin David!
  • Picture of Rogier Dikkes
    Mon, Apr 15, 2013, 8:02 PM
    Hi Sam,

    Will this eventually become part of the core like the MUC for memcached?
  • Sam@moodle
    Tue, Apr 16, 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
    Sam
  • Picture of Lael ...
    Fri, May 24, 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?

    Thanks!
  • Sam@moodle
    Fri, May 24, 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
    Sam
  • Picture of Andrew Chapman
    Thu, Jul 18, 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.
Please login to post comments