Note: You are currently viewing documentation for Moodle 2.5. Up-to-date documentation for the latest stable version of Moodle may be available here: Caching.
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.
Moodle 2.4 saw the implementation of MUC, the Moodle Universal Cache. This new system allows certain functions of Moodle (eg string fetching) take advantage of different installed cache services (eg files, ram, memcached).
In future versions of Moodle we will continue expanding the number of Moodle functions that use MUC, which will continue improving performance, but you can already start using it to improve your site.
- 1 General approach to performance testing
- 2 How to use the caching settings
- 3 Cache definition configuration
- 3.1 Language string cache
- 3.2 Database meta information
- 3.3 Event invalidation
- 3.4 Question definitions
- 3.5 HTML Purifier - cleaned content
- 3.6 Config settings
- 3.7 Course group information
- 3.8 Calendar subscriptions
- 3.9 YUI Module definitions
- 3.10 Plugin types
- 3.11 Plugin list Application
- 3.12 Plugin info - base
- 3.13 Plugin info - activity modules
- 3.14 Plugin info - blocks
- 3.15 Plugin info - filters
- 3.16 Plugin info - repositories
- 3.17 Plugin info - portfolios
- 3.18 Course categories tree
- 3.19 Course categories lists for particular user
- 3.20 Course categories records
- 3.21 List of course contacts
- 3.22 Repositories instances data
- 4 Stores used when no mapping is present
- 5 Other performance testing
- 6 Performance advise for Moodle 2.5 with load-balanced web servers
- 7 See also
General approach to performance testing
Here is the general strategy you should be taking:
- Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)
- Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)
- Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).
- Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)
- Run your load and measure a baseline performance result.
- Change one variable at a time, and re-run the load to see if performance gets better or worse. Repeat as necessary.
- When you discover settings that result in a consistent performance improvement, apply to your production site.
How to use the caching settings
Since Moodle 2.4, Moodle has provided a caching plugin framework to give administrators the ability to control where Moodle stores cached data. For most Moodle sites the default configuration should be sufficient and it is not necessary to change the configuration. For larger Moodle sites with multiple servers, administrators may wish to use memcached, mongodb or other systems to store cache data. The cache plugin screen provides administrators with the ability to configure what cache data is stored where.
Types of cache
Moodle uses three types of cache to store cached data:
- Request cache - The request cache is available for the duration of every page request. It is not shared between users and is used and cleared on every Moodle request.
- Session cache - The session cache is available through a users session in Moodle. It is not shared between users, but persists for a single user throughout their session (i.e. from when they logon til when they log off)
- Application cache - The application cache is a shared cache which is available for every request. It can be shared between users and the cached data can be kept indefinitely if required.
Cache types and multiple-server systems
If you have a system with multiple front-end web servers, the application cache must be shared between the servers. In other words, you cannot use fast local storage for the application cache, but must use shared storage or some other form of shared cache such as a shared memcache.
The same applies to session cache, unless you use a 'sticky sessions' mechanism to ensure that within a session, users always access the same front-end server.
Installed cache stores
This section of the administrator screen displays cache plugins which are installed on the system. It lists what the capabilities of each plugin, what type of cache they provide and provides allows a cache store to be added to the system.
Configured store instances
This section of the administrator screen displays cache stores which have been added to the system. It gives the ability to change the cache configuration and purge the cached data.
Cache lock instances
Moodle supports different mechanisms for 'locking' access to the various cache stores. At present there is only one option and it is not used, so it can safely be ignored.
Known cache definitions
Known cache definitions displays the caches which are in use by Moodle. Each item is an area of Moodle which is using caching. It gives the administrator the ability to configure an individual area of Moodle to use a different cache backend. For example, an administrator of a Moodle cluster may choose to make language string definitions be cached on a dedicated memcached server by using the memcached cache backend. See the section below for more information about configuring these.
Cache definition configuration
Each different cache can be configured independently, allowing admins to "tune" their setup for particular systems.
By default these caches are all set to use files, which is usually fine on a small one-server system.
On a cluster, however, these defaults can cause problems because shared filesystems are slow, so in these cases we recommend you use a faster shared caching backend like memcached instead. Note that most of these caches operating under the assumption that they are shared.
In some cases you can choose to use a non-shared cache like the local filesystem however in these instances you be careful to purge caches MANUALLY as part of system administration.
The following reference is intended to help you understand how each caching definition works so you can tune appropriately:
Language string cache
- What is cached:
- When the cache is updated:
- How often it is hit:
- When should the cache be purged completely:
Database meta information
HTML Purifier - cleaned content
Course group information
YUI Module definitions
Plugin list Application
Plugin info - base
Plugin info - activity modules
Plugin info - blocks
Plugin info - filters
Plugin info - repositories
Plugin info - portfolios
Course categories tree
Course categories lists for particular user
Course categories records
List of course contacts
Repositories instances data
Stores used when no mapping is present
This section displays the default cache stores which should be used by Moodle for each type of Moodle cache. If a mapping for a cache definition does not exist then this default store will be used instead.
Other performance testing
Two links that might be useful to anyone considering testing performance on their own servers:
- Moodle performance testing: how much more horsepower do each new versions of Moodle require?
- How to load test your Moodle server using Loadstorm
Performance advise for Moodle 2.5 with load-balanced web servers
Performance advice: if you are running Moodle 2.4 onwards with load-balanced web servers, don't use the default caching option that stores the data in moodledata on a shared network drive. Use memcache instead. See Tim Hunt's article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html.
Using Moodle forum discussions: