<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="sv">
	<id>https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Samhemelryk</id>
	<title>MoodleDocs - Användarbidrag [sv]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Samhemelryk"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/Special:Bidrag/Samhemelryk"/>
	<updated>2026-04-23T23:56:04Z</updated>
	<subtitle>Användarbidrag</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113105</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113105"/>
		<updated>2014-06-12T03:32:01Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core. This information will likely be of most use to those administrators who are really trying to get the most out the caching system in Moodle. The information about each cache should help in deciding which backends to use for which definitions.&lt;br /&gt;
&lt;br /&gt;
For small sites, or those running on a single server likely adopting a single backend such as memcache is going to give you an immediate performance boost.&amp;lt;br /&amp;gt;&lt;br /&gt;
However with a bit of planning and some careful mapping likely you can improve things further.&lt;br /&gt;
&lt;br /&gt;
==What you will find in this document==&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If shared between sites please be aware that any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113104</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113104"/>
		<updated>2014-06-12T03:31:28Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core. This information will likely be of most use to those administrators who are really trying to get the most out the caching system in Moodle. The information about each cache should help in deciding which backends to use for which definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
For small sites, or those running on a single server likely adopting a single backend such as memcache is going to give you an immediate performance boost.&amp;lt;br /&amp;gt;&lt;br /&gt;
However with a bit of planning and some careful mapping likely you can improve things further.&lt;br /&gt;
&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If shared between sites please be aware that any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113103</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113103"/>
		<updated>2014-06-12T03:30:53Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core. This information will likely be of most use to those administrators who are really trying to get the most out the caching system in Moodle. The information about each cache should help in deciding which backends to use for which definitions.&lt;br /&gt;
&lt;br /&gt;
For small sites, or those running on a single server likely adopting a single backend such as memcache is going to give you an immediate performance boost.&amp;lt;br /&amp;gt;&lt;br /&gt;
However with a bit of planning and some careful mapping likely you can improve things further.&lt;br /&gt;
&lt;br /&gt;
==What can be found here==&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If shared between sites please be aware that any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113102</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113102"/>
		<updated>2014-06-12T03:24:00Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* More information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use those servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
===More on performance testing===&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
===Performance advice for load-balanced web servers===&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==Troubleshooting==&lt;br /&gt;
&lt;br /&gt;
Have you encountered a problem, or found yourself in a conundrum? Perhaps the answer is in this section. If its not when you find have an answer how about sharing it here.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113101</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113101"/>
		<updated>2014-06-12T03:21:54Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Other performance advice for load-balanced web servers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use those servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
===More on performance testing===&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
===Performance advice for load-balanced web servers===&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113100</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113100"/>
		<updated>2014-06-12T03:21:23Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Other performance testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use those servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
===More on performance testing===&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113099</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113099"/>
		<updated>2014-06-11T23:58:43Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Mapping a cache to a store instance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use those servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
You are presented with several drop-downs that allow you to map one or more cached. All mapped caches get interacted with. The &amp;quot;Primary&amp;quot; store is the store that will be used first when interacting with the cache.&lt;br /&gt;
The &amp;quot;Final&amp;quot; mapped store will be the last cache store interacted with.&amp;lt;br /&amp;gt;&lt;br /&gt;
How this interaction occurs is documented below.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113098</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113098"/>
		<updated>2014-06-11T23:49:52Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Memcache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use those servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113097</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113097"/>
		<updated>2014-06-11T23:49:10Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Memcached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use a dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use it. Doing so may lead to performance deprecation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcached extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this it is important to note that when you purge a Memcached store within Moodle it deletes ALL entries in the Memcached server. Not just those relating to Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
For that reason it is highly recommended to use dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use the same servers. Doing so may lead to performance depreciation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcached for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113096</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113096"/>
		<updated>2014-06-11T23:47:49Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Memcache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important implementation notes&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The Memcache extension does not provide a means of deleting a set or entries. Either a single entry is deleted, or all entries are deleted.&amp;lt;br /&amp;gt;Because of this it is important to note that when you purge a Memcache store within Moodle it deletes ALL entries in the Memcache backend. Not just those relating to Moodle.&amp;lt;br /&amp;gt;For that reason it is highly recommended to use a dedicated Memcached servers and to &#039;&#039;&#039;NOT&#039;&#039;&#039; configure any other software to use it. Doing so may lead to performance deprecation and adverse affects.&lt;br /&gt;
* Likewise if you want to use Memcache for caching and for sessions in Moodle it is essential to use two Memcached servers. One for sessions, and one for caching. Otherwise a cache purge in Moodle will purge your sessions!&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113095</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113095"/>
		<updated>2014-06-11T23:33:25Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Stores used when no mapping is present */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are no specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
To simplify that, this show the default cache stores for each type.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113094</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=113094"/>
		<updated>2014-06-11T23:24:20Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Language string cache */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If shared between sites please be aware that any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113093</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=113093"/>
		<updated>2014-06-11T23:21:03Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Added note about language customisations in regards to sharing.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar with, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that get used when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it. A cache by nature is volatile and any information that is absolutely mission critical should be a more permanent data store likely the database.&lt;br /&gt;
&lt;br /&gt;
Nonetheless there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share in many situations, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is important to consider with the language cache that by sharing it between sites any language customisations will also be shared.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. It is useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve your sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mongodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column select the link for &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Scenario:&lt;br /&gt;
You have have a web server that has a Moodle site as well as other sites.&lt;br /&gt;
You also have a Memcache server that is used by several sites including Moodle.&lt;br /&gt;
&lt;br /&gt;
Memcache has a limited size cache, that when full and requested to store more information frees space by dropping the least used cache entries.&lt;br /&gt;
&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step-by-step guide to this.&lt;br /&gt;
&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered are some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&lt;br /&gt;
&lt;br /&gt;
If you are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-08-add-memcache-store.png&amp;diff=113004</id>
		<title>Fil:caching-27-08-add-memcache-store.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-08-add-memcache-store.png&amp;diff=113004"/>
		<updated>2014-06-09T01:46:21Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of adding a Memcache store instance.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of adding a Memcache store instance.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-12-default-store-mapping.png&amp;diff=113003</id>
		<title>Fil:caching-27-12-default-store-mapping.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-12-default-store-mapping.png&amp;diff=113003"/>
		<updated>2014-06-09T01:45:41Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of default store mappings.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of default store mappings.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-11-store-mapping.png&amp;diff=113002</id>
		<title>Fil:caching-27-11-store-mapping.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-11-store-mapping.png&amp;diff=113002"/>
		<updated>2014-06-09T01:45:18Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of store mappings.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of store mappings.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-10-add-mongodb-store.png&amp;diff=113001</id>
		<title>Fil:caching-27-10-add-mongodb-store.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-10-add-mongodb-store.png&amp;diff=113001"/>
		<updated>2014-06-09T01:45:03Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of adding a Mongodb store instance.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of adding a Mongodb store instance.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-09-add-memcached-store.png&amp;diff=113000</id>
		<title>Fil:caching-27-09-add-memcached-store.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-09-add-memcached-store.png&amp;diff=113000"/>
		<updated>2014-06-09T01:44:53Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of adding a Memcached store instance.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of adding a Memcached store instance.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-07-add-file-cache-store.png&amp;diff=112999</id>
		<title>Fil:caching-27-07-add-file-cache-store.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-07-add-file-cache-store.png&amp;diff=112999"/>
		<updated>2014-06-09T01:44:29Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of adding a new file cache store instance.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of adding a new file cache store instance.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-06-stores-used-when-no-mapping-is-present.png&amp;diff=112998</id>
		<title>Fil:caching-27-06-stores-used-when-no-mapping-is-present.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-06-stores-used-when-no-mapping-is-present.png&amp;diff=112998"/>
		<updated>2014-06-09T01:44:05Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of default stores in cache configuration screen.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of default stores in cache configuration screen.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-05-summary-of-cache-lock-instances.png&amp;diff=112997</id>
		<title>Fil:caching-27-05-summary-of-cache-lock-instances.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-05-summary-of-cache-lock-instances.png&amp;diff=112997"/>
		<updated>2014-06-09T01:43:30Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of cache lock instances in cache configuration screen.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of cache lock instances in cache configuration screen.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-04-known-cache-definitions.png&amp;diff=112996</id>
		<title>Fil:caching-27-04-known-cache-definitions.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-04-known-cache-definitions.png&amp;diff=112996"/>
		<updated>2014-06-09T01:43:05Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of known cache definitions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of known cache definitions.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-03-configured-store-instances.png&amp;diff=112995</id>
		<title>Fil:caching-27-03-configured-store-instances.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-03-configured-store-instances.png&amp;diff=112995"/>
		<updated>2014-06-09T01:42:50Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of installed cache store instances.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of installed cache store instances.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-02-installed-cache-stores.png&amp;diff=112994</id>
		<title>Fil:caching-27-02-installed-cache-stores.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-02-installed-cache-stores.png&amp;diff=112994"/>
		<updated>2014-06-09T01:42:29Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Screenshot of installed cache stores&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of installed cache stores&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112993</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112993"/>
		<updated>2014-06-09T01:41:48Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Update images&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:caching-27-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-01-configuration-screen.png&amp;diff=112992</id>
		<title>Fil:caching-27-01-configuration-screen.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Fil:caching-27-01-configuration-screen.png&amp;diff=112992"/>
		<updated>2014-06-09T01:39:58Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Cache configuration screen in Moodle 2.7&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Cache configuration screen in Moodle 2.7&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112991</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112991"/>
		<updated>2014-06-09T01:33:38Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Configuring caching for your site */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112989</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112989"/>
		<updated>2014-06-09T01:32:35Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Known cache definitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here yet. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
Information on specific cache definitions can be found on the [[Cache definitions]] page.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112988</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112988"/>
		<updated>2014-06-09T01:30:35Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* More information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is a list of all the caches within Moodle that have a definition.&amp;lt;br /&amp;gt;&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112987</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112987"/>
		<updated>2014-06-09T01:30:05Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* More information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API|Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference|Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)|The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112986</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112986"/>
		<updated>2014-06-09T01:29:18Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Repositories instances data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)]] The original cache specification.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112985</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112985"/>
		<updated>2014-06-09T01:28:25Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Better formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; When this cache definition was first introduced into Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Which users can expect to benefit from the cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursemodinfo&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039;  core, calendar_subscriptions&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44366)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; mod_glossary, concepts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone when the glossary filter is enabled.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, config&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every page, without fail.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecattree&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34398)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, groupdata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; all users accessing a course in which groups are used.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, databasemeta&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, eventinvalidation&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-39846)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, observers&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, externalbadges&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability_grade, items&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, htmlpurifier&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-25290)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, string&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, on every browsable page within Moodle.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-41019)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, langmenu&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, determined by the number of languages installed on the site.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38596)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecontacts&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34401)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, plugin_manager&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators primarily.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.4 (MDL-34399)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, questiondata&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, gradecondition&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.7 (MDL-44070)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; availability, scores&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38391)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, yuimodules&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecat&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-42299)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, userselections&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-30740)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; repository_skydrive, foldername &lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-38147)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, coursecatrecords&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.6 (MDL-13114)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; tool_uploadcourse, helper&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; Administrators&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Since:&#039;&#039;&#039; Moodle 2.5 (MDL-34346)&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Component/Area:&#039;&#039;&#039; core, repositories&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Growth:&#039;&#039;&#039; ?&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Who:&#039;&#039;&#039; logged in users with one or more accessible repositories.&lt;br /&gt;
&amp;lt;br /&amp;gt;&#039;&#039;&#039;Priority:&#039;&#039;&#039; ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112984</id>
		<title>Cache definitions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cache_definitions&amp;diff=112984"/>
		<updated>2014-06-09T01:25:01Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Created page with &amp;quot;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt; Each cache definition found within core will be under its own heading and will include a description...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information on the cache definitions within core.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each cache definition found within core will be under its own heading and will include a description of the cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
As well as the name and description the following information will also be details:&lt;br /&gt;
&lt;br /&gt;
; Since : When this cache definition was first introduced into Moodle.&lt;br /&gt;
; Component/Area : The code component this cache belongs to and the area (unique simple name) given to it.&lt;br /&gt;
; Growth : Will state if this cache is expected to be of fixed size, or can be expected to grow as the site data grows. Perhaps some information on how the cache will grow.&lt;br /&gt;
; Who : Which users can expect to benefit from the cache.&lt;br /&gt;
; Priority : An indication of the anticipated cache use on a site. A value between 1 and 5. If the cache is of fixed size and is accessed expected to be utilised on every page it will be given a 5 for priority as it can be expected that assigning that cache to the fastest backend available would be the good idea. In contrast a priority of 1 would be given to a cache that is expected to grow quickly, is only accessed on specific pages, and only applies to some users (e.g. teachers, or the admin). This cache should be the least of your concerns when deciding upon how to implement caching on your site.&lt;br /&gt;
&lt;br /&gt;
==A note about cache configuration on large sites==&lt;br /&gt;
Each different cache can be configured independently, allowing admins to &amp;quot;tune&amp;quot; their setup for particular systems.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default these caches are all set to use the file system, which is usually fine on a small one-server system.&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Application caches==&lt;br /&gt;
Application caches are shared caches.&lt;br /&gt;
&lt;br /&gt;
===Accumulated information about modules and sections for each course===&lt;br /&gt;
&lt;br /&gt;
Accumulated information about course modules, and sections used to print the course page as well as in calls to &#039;&#039;get_fast_modinfo()&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache gets forcefully reset within &#039;&#039;rebuild_course_cache()&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This is an excellent cache to optimise caching for on a production site.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is accessed primarily for the course view page, and very frequently hit and often expensive page and it is utilised within &#039;&#039;get_fast_modinot()&#039;&#039; a function that is called often in Moodle when querying or displaying information on a course, section or activity.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6&lt;br /&gt;
; Component/Area : core, coursemodinfo&lt;br /&gt;
; Growth : exponential, the number of courses, sections within those courses, and activities within each section will determine the size of this cache.&lt;br /&gt;
; Who : everyone. This cache isn&#039;t accessed on every page, however as its associated with courses you can expect its accces to still be high.&lt;br /&gt;
; Priority : 4&lt;br /&gt;
&lt;br /&gt;
===Calendar subscriptions===&lt;br /&gt;
&lt;br /&gt;
Caches calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a very simple cache that stores the calendar subscription records from the database for quick, specific access.&lt;br /&gt;
&lt;br /&gt;
This should be considered a low priority cache unless your users are likely to be creating many calendar subscriptions.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is going to be very small, should you have lots of calendar subscriptions mapping this cache definition to a fast, but small backend would be ideal.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5&lt;br /&gt;
; Component/Area :  core, calendar_subscriptions&lt;br /&gt;
; Growth : determined by the number of calendar subscriptsion created by users. Entirely dependent on your users.&lt;br /&gt;
; Who : everyone who has a calendar subscript, on calendar pages, or pages where the calendar block is being displayed.&lt;br /&gt;
; Priority : 1&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* What is cached:- Record entries from &#039;event_subscriptions&#039; table, representing various calendar subscriptions.&lt;br /&gt;
* When the cache is updated:- When a calendar subscription is updated or deleted.&lt;br /&gt;
* How often it is hit:- Everytime a calendar subscription detail is fetched.&lt;br /&gt;
* When should the cache be purged completely:- This should not be needed.&lt;br /&gt;
&lt;br /&gt;
===Concept linking [mod_glossary]===&lt;br /&gt;
&lt;br /&gt;
Caches concepts for the glossary filter.&lt;br /&gt;
&lt;br /&gt;
Concepts are cached in relation to either the site or a course. The course ID is used as the key if they are for a course, 0 is used as the key for site concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry in the cache is an array consisting of two items, the first is an array of glossaries, the second an array of concepts.&amp;lt;br /&amp;gt;&lt;br /&gt;
The actual data being stored is minimal, even on a large site the storage requirement for this cache should be relatively small.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039; This cache CANNOT be a local cache, it must be shared.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.7 (MDL-44366)&lt;br /&gt;
; Component/Area : mod_glossary, concepts&lt;br /&gt;
; Growth : exponential, the number of glossaries, and the number of terms within those glossaries will determine the size of this cache.&lt;br /&gt;
; Who : everyone when the glossary filter is enabled.&lt;br /&gt;
; Priority : 3&lt;br /&gt;
&lt;br /&gt;
===Config settings===&lt;br /&gt;
&lt;br /&gt;
Caches the configuration for the site. This is the administration settings in both core and all plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is going to be accessed on every single page within Moodle, regradless of the users state or what is being done.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should map this cache to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4&lt;br /&gt;
; Component/Area : core, config&lt;br /&gt;
; Growth : fixed, the number of items is the number of settings in core and all installed plugins. This will only increase as settings are introduced or removed.&lt;br /&gt;
; Who : everyone, on every page, without fail.&lt;br /&gt;
; Priority : 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* This cache is hit quite often for getting config settings.&lt;br /&gt;
&lt;br /&gt;
===Course categories tree===&lt;br /&gt;
&lt;br /&gt;
This cache stores the full course categories tree.&lt;br /&gt;
&lt;br /&gt;
It is often used when navigating the course category structure and you can expect it to be hit in situations where either the full tree, or part of the tree is displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This includes some elements that can be configured to display on the front page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its use will be determinent on how you have configured Moodle and what is set to be displayed.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-38147)&lt;br /&gt;
; Component/Area : core, coursecattree&lt;br /&gt;
; Growth : fixed, will be limited to the number of course categories on your site. During course creation this site will obviously grow, but in day to day use it should remain static.&lt;br /&gt;
; Who : everyone.&lt;br /&gt;
; Priority : 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Gets invalidated when changesincoursecat event is triggered.&lt;br /&gt;
&lt;br /&gt;
===Course group information===&lt;br /&gt;
&lt;br /&gt;
Caches grouping information for courses.&lt;br /&gt;
&lt;br /&gt;
Information is cached in relation to a course and is very simple. It is only used in situations where a course has defined groups and those groups are being used.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache can be expected to save 1 - 2 queries per page.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-34398)&lt;br /&gt;
; Component/Area : core, groupdata&lt;br /&gt;
; Growth : fixed, the number of courses and groups within those courses determines the size of this cache.&lt;br /&gt;
; Who : all users accessing a course in which groups are used.&lt;br /&gt;
; Priority : 2&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Gets updated when groups data is fetched for a course.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Database meta information===&lt;br /&gt;
&lt;br /&gt;
Caches meta information on database tables including information about columns.&lt;br /&gt;
&lt;br /&gt;
This cache is a priority cache, it is accessed on nearly every page within Moodle and its operation can be expensive.&amp;lt;br /&amp;gt;&lt;br /&gt;
Each entry uses the table name as the key and the cached data is the structure of the database table.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4 (MDL-25290)&lt;br /&gt;
; Component/Area : core, databasemeta&lt;br /&gt;
; Growth : fixed, the number of database tables determines the size of this cache and may only change during upgrade and installation/deletion of plugins.&lt;br /&gt;
; Who : everyone&lt;br /&gt;
; Priority : 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Requires shared cache&lt;br /&gt;
* If not shared, caches need to be invalidated after any DB structure change including creation of temporary tables.&lt;br /&gt;
&lt;br /&gt;
===Event invalidation===&lt;br /&gt;
&lt;br /&gt;
This cache is used to manage event invalidation for the MUC API. This is an internal API and has no relation what so ever to the Event API introduced in 2.7.&lt;br /&gt;
&lt;br /&gt;
This is not often used within Moodle and when it is used occurs when editing happens and multiple caches need to purged, not all of which may be shared and some which may be cleared when the user next touches the cache.&lt;br /&gt;
The overall cache size should be relatively small, and as checking often occurs for these caches on page access it is recommended to map this cache to a fast backend.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4 (MDL-25290)&lt;br /&gt;
; Component/Area : core, eventinvalidation&lt;br /&gt;
; Growth : fixed, events are subscribed to by definitinos and will only change during upgrade and the installation and deletion of plugins.&lt;br /&gt;
; Who : everyone, events get triggered by action and in disconnected caches this be not be reflected until the user next hits the page.&lt;br /&gt;
; Priority : 4&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* Whenever something is invalidated, it is purged immediately and an event record is created with the timestamp.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Event observers===&lt;br /&gt;
&lt;br /&gt;
This cache is used for storing list of event observers.&lt;br /&gt;
&lt;br /&gt;
It is updated on install/update while initialising list of event observers.&amp;lt;br /&amp;gt;&lt;br /&gt;
This cache is accessed, when event is trigged.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6 (MDL-39846)&lt;br /&gt;
; Component/Area : core, observers&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===External badges for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store external badges.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5.2, 2.6 (MDL-40924)&lt;br /&gt;
; Component/Area : core, externalbadges&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
===Grade items cached for evaluating conditional availability [availability_grade, items]===&lt;br /&gt;
&lt;br /&gt;
Used to cache course grade items for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.7 (MDL-44070)&lt;br /&gt;
; Component/Area : availability_grade, items&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
===HTML Purifier - cleaned content===&lt;br /&gt;
&lt;br /&gt;
This is a cache of texts (forum posts, resources, intros etc etc) from all parts of Moodle, after it has been cleaned of possible malicious data.&lt;br /&gt;
&lt;br /&gt;
Caches cleaned text in relation to user + context of the text being cleaned.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; This data may be safetly stored in local caches on clusted nodes.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4.2, 2.5 (MDL-36297)&lt;br /&gt;
; Component/Area : core, htmlpurifier&lt;br /&gt;
; Growth : exponential, cleaned content is usually stored once for each user + context combination.&lt;br /&gt;
; Who : everyone&lt;br /&gt;
; Priority : 3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.5,&lt;br /&gt;
* This expects a shared cache&lt;br /&gt;
* If not shared, must be manually purged after every upgrade or change of $CFG-&amp;gt;allowobjectembed setting&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later,&lt;br /&gt;
* This works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===Language string cache===&lt;br /&gt;
&lt;br /&gt;
The language string cache is one of the most essential caches within Moodle, it caches each and every language file used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its of fixed size as there are a finite number of languages and language files and as it is accessed one pretty much every page within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is a prime cache to configure, map it to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
The string cache uses the a hash of the revision, language, and component of a language file as the key, and the array found within the corrosponding file is the data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Static acceleration is used on this cache to speed up subsequent request for a string within a given language file. This is essential as string are usually requested one by one and often only from a handful of language files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039; Cache usage differs greatly between Admins + managers and teacher + students. Admins and managers being able to complete more actions and often across difference components and plugins often require that many more language files be accessed for a page than a user such as a teacher or student require.&amp;lt;br /&amp;gt;&lt;br /&gt;
When testing your cache configuration ensure you test as a student.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4 (MDL-25290)&lt;br /&gt;
; Component/Area : core, string&lt;br /&gt;
; Growth : fixed size, each language string file is cached here, its size will be fixed but will be determined by the number of languages available on your site.&lt;br /&gt;
; Who : everyone, on every browsable page within Moodle.&lt;br /&gt;
; Priority : 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.4 and Moodle 2.6:&lt;br /&gt;
* Expects shared cache.&lt;br /&gt;
* If not shared it must be manually purged after any language string change such as editing of local lang packs, updating of lang packs during upgrade, installation or uninstallation of languages. &lt;br /&gt;
&lt;br /&gt;
In Moodle 2.6 and later:&lt;br /&gt;
* Works fine with local or shared node caches, you don&#039;t have to do anything special.&lt;br /&gt;
&lt;br /&gt;
===List of available languages===&lt;br /&gt;
&lt;br /&gt;
Caches a list of available languages.&lt;br /&gt;
&lt;br /&gt;
This list of languages is used every time the list of languages is requested in a page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Because of this the cache will be hit by on many pages within Moodle on any site with more than one language installed.&lt;br /&gt;
As its a small, fixed size cache on a site with multiple languages installed its a good idea to map this to the fastest backend you&#039;ve got available.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6 (MDL-41019)&lt;br /&gt;
; Component/Area : core, langmenu&lt;br /&gt;
; Growth : fixed, determined by the number of languages installed on the site.&lt;br /&gt;
; Who : everyone&lt;br /&gt;
; Priority : 4&lt;br /&gt;
&lt;br /&gt;
===List of course contacts===&lt;br /&gt;
&lt;br /&gt;
Used to cache course contacts.&lt;br /&gt;
&lt;br /&gt;
Course contacts are displayed in several places throughout Moodle, they are in most situations considered public information (like course names) and can be seeing by all users.&amp;lt;br /&amp;gt;&lt;br /&gt;
The process of listing these course contacts can be expensive, however the course contacts are shown only on select pages.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-38596)&lt;br /&gt;
; Component/Area : core, coursecontacts&lt;br /&gt;
; Growth : the number of courses and the number of users with course contact roles determines this size of this cache.&lt;br /&gt;
; Who : everyone, course contacts are public information and may be displayed in several places throughout Moodle that can be accessed by anyone.&lt;br /&gt;
; Priority : 3&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering/searching course&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Plugin info manager===&lt;br /&gt;
&lt;br /&gt;
Caches information on installed plugins, enabled plugins, and present plugins.&lt;br /&gt;
&lt;br /&gt;
This cache is heavily used when managing plugins for site through the admin interfaces.&amp;lt;br /&amp;gt;&lt;br /&gt;
Primarily people accessing this page benefit from the existence of this cache.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This must be a shared cache.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-34401)&lt;br /&gt;
; Component/Area : core, plugin_manager&lt;br /&gt;
; Growth : fixed, the number of plugins determines the size of this cache.&lt;br /&gt;
; Who : Administrators primarily.&lt;br /&gt;
; Priority : 2&lt;br /&gt;
&lt;br /&gt;
====Plugin info - base====&lt;br /&gt;
* This cache is used by plugininfo_base class and stores plugin information.&lt;br /&gt;
* This is accessed while loading/checking plugin versions from disk.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - activity modules====&lt;br /&gt;
* This cache is used by plugininfo_mod class and provide access to records in modules table.&lt;br /&gt;
* This is accessed while loading/checking modules.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - blocks====&lt;br /&gt;
* This cache is used by plugininfo_block class and provide access to records in block table.&lt;br /&gt;
* This is accessed while loading/checking blocks.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - filters====&lt;br /&gt;
* This cache is used by plugininfo_filter class and stores names of all filters installed.&lt;br /&gt;
* This is accessed while loading/checking installed filters.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - repositories====&lt;br /&gt;
* This cache is used by plugininfo_repositories class and provide access to records in repository table.&lt;br /&gt;
* This is accessed while loading enabled repositories.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
====Plugin info - portfolios====&lt;br /&gt;
* This cache is used by plugininfo_portfolio class and stores list of enabled portfolio plugins.&lt;br /&gt;
* This is accessed while checking if portfolio is enabled.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===Question definitions===&lt;br /&gt;
&lt;br /&gt;
Caches question definitions. This is used by the question bank class.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.4 (MDL-34399)&lt;br /&gt;
; Component/Area : core, questiondata&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
* This gets updated when question is loaded or edited.&lt;br /&gt;
* Doesn&#039;t require data guarantee.&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability===&lt;br /&gt;
&lt;br /&gt;
; Since : &lt;br /&gt;
; Component/Area : core, gradecondition&lt;br /&gt;
; Growth : &lt;br /&gt;
; Who : &lt;br /&gt;
; Priority : &lt;br /&gt;
&lt;br /&gt;
===User grades cached for evaluating conditional availability [availability_grade, scores]===&lt;br /&gt;
&lt;br /&gt;
Used to cache user grades for conditional availability purposes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; This cache sets a TTL (Time To Live) of 3600 (1 hour).&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.7 (MDL-44070)&lt;br /&gt;
; Component/Area : availability, scores&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
===YUI Module definitions===&lt;br /&gt;
&lt;br /&gt;
Caches information on shifter YUI modules used within Moodle when JS caching is enabled.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-38391)&lt;br /&gt;
; Component/Area : core, yuimodules&lt;br /&gt;
; Growth : fixes, the number of Moodle  YUI modules within core and plugins. This will only change during upgrade, or installation/removal of plugins.&lt;br /&gt;
; Who : everyone, this is used when ever Moodle YUI modules are used on a page and that is most pages as of 2.8.&lt;br /&gt;
; Priority : 5&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
&lt;br /&gt;
==Session caches==&lt;br /&gt;
Data cached here belongs to the user browsing the site.&lt;br /&gt;
&lt;br /&gt;
===Course categories lists for particular user===&lt;br /&gt;
&lt;br /&gt;
Used to store data for course categories visible to current user. Helps to browse list of categories.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is also used during course category management.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-38147)&lt;br /&gt;
; Component/Area : core, coursecat&lt;br /&gt;
; Growth : the number of categories and courses on the site that the user can see will determine the size of this for the current user.&lt;br /&gt;
; Who : everyone, it is used within several front page elements.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires shared cache.&lt;br /&gt;
* Is invalidated when changesincoursecat or changesincourse event is trigged.&lt;br /&gt;
&lt;br /&gt;
===Data used to persist user selections throughout Moodle===&lt;br /&gt;
&lt;br /&gt;
Caches user selections that should persist for the lifetime of the users log in. This includes things like which categories the user has expanded in the course category management page.&amp;lt;br /&amp;gt;&lt;br /&gt;
Think of them like user preferences but with limited lifetime.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6 (MDL-42299)&lt;br /&gt;
; Component/Area : core, userselections&lt;br /&gt;
; Growth : exponential, depends upon how much the user interacts with things like expading categories.&lt;br /&gt;
; Who : logged in users.&lt;br /&gt;
&lt;br /&gt;
===Folder name cache [repository_skydrive]===&lt;br /&gt;
&lt;br /&gt;
?&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6 (MDL-30740)&lt;br /&gt;
; Component/Area : repository_skydrive, foldername &lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : ?&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
==Request caches==&lt;br /&gt;
Caches here last only for the life time of the request and are only available to the browsing user.&lt;br /&gt;
&lt;br /&gt;
===Course categories records===&lt;br /&gt;
&lt;br /&gt;
Caches a list of course categories visible to the user.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-38147)&lt;br /&gt;
; Component/Area : core, coursecatrecords&lt;br /&gt;
; Growth : fixes, the number of categories on the site visible to the user will determine this.&lt;br /&gt;
; Who : everyone&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This is accessed while rendering course category.&lt;br /&gt;
* Is invalidated when changesincoursecat event is triggered.&lt;br /&gt;
* Require local cache.&lt;br /&gt;
&lt;br /&gt;
===Helper caching [tool_uploadcourse]===&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.6 (MDL-13114)&lt;br /&gt;
; Component/Area : tool_uploadcourse, helper&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : Administrators&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
===Repositories instances data===&lt;br /&gt;
&lt;br /&gt;
Used to cache data on configured repositories to avoid repetitive database calls to load repositories.&lt;br /&gt;
&lt;br /&gt;
; Since : Moodle 2.5 (MDL-34346)&lt;br /&gt;
; Component/Area : core, repositories&lt;br /&gt;
; Growth : ?&lt;br /&gt;
; Who : logged in users with one or more accessible repositories.&lt;br /&gt;
; Priority : ?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes for advanced, multi-server sites&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Requires local cache.&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112983</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112983"/>
		<updated>2014-06-09T01:24:33Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* More information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is a list of all the caches within Moodle that have a definition.&amp;lt;br /&amp;gt;&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112982</id>
		<title>Caching</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Caching&amp;diff=112982"/>
		<updated>2014-06-09T01:23:25Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Massive changes to really beef up the caching documentation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
&lt;br /&gt;
A cache is a collection of processed data that is kept on hand and re-used in order to avoid costly repeated database queries.&lt;br /&gt;
&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==General approach to performance testing==&lt;br /&gt;
&lt;br /&gt;
Here is the general strategy you should be taking:&lt;br /&gt;
&lt;br /&gt;
# Build a test environment that is as close to your real production instance as possible (eg hardware, software, networking, etc)&lt;br /&gt;
# Make sure to remove as many uncontrolled variables as you can from this environment (eg other services)&lt;br /&gt;
# Use a tool to place a realistic, but simulated and repeatable load upon you server. (eg jmeter or selenium).&lt;br /&gt;
# Decide on a way to measure performance of the server by capturing data (ram, load, time taken, etc)&lt;br /&gt;
# Run your load and measure a baseline performance result.&lt;br /&gt;
# Change one variable at a time, and re-run the load to see if performance gets better or worse.  Repeat as necessary.&lt;br /&gt;
# When you discover settings that result in a consistent performance improvement, apply to your production site.&lt;br /&gt;
&lt;br /&gt;
==Cache configuration in Moodle==&lt;br /&gt;
&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
Caching in Moodle is controlled by what is known as the Moodle Universal Cache. Commonly referred to MUC.&lt;br /&gt;
&lt;br /&gt;
This document explains briefly what MUC is before proceeding into detail about the concepts and configuration options it offers.&lt;br /&gt;
&lt;br /&gt;
==The basic cache concepts in Moodle==&lt;br /&gt;
Caching in Moodle isn&#039;t as complex as it first appears. A little background knowledge will go a long way in understanding how cache configuration works.&lt;br /&gt;
&lt;br /&gt;
===Cache types===&lt;br /&gt;
Lets start with cache types (sometimes referred to as mode). There are three basic types of caches in Moodle.&lt;br /&gt;
&lt;br /&gt;
The first is the application cache. This is by far the most commonly used cache type in code. Its information is shared by all users and its data persists between requests. Information stored here is usually cached for one of two reasons, either it is required information for the majority of requests and saves us a one of more database interactions or it is information that is accessed less frequently but is resource intensive to generate.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default this information is stored in an organised structure within your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The second cache type is the session cache. This is just like the PHP session that you will already be familiar, in fact it uses the PHP session by default. You may be wondering why we have this cache type at all, but the answer is simple. MUC provides a managed means of storing, and removing information that is required between requests. It offers developers a framework to use rather than having to re-invent the wheel and ensures that we have access to a controlled means of managing the cache as required.&amp;lt;br /&amp;gt;&lt;br /&gt;
Its important to note that this isn&#039;t a frequently used cache type as by default session cache data is stored in the PHP session and the PHP session is stored in the database. Uses of the session cache type are limited to small datasets as we don&#039;t want to bloat sessions and thus put strain on the database.&lt;br /&gt;
&lt;br /&gt;
The third and final type is the request cache. Data stored in this cache type only persists for the lifetime of the request. If you&#039;re a PHP developer think of it like a managed static variable.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is by far the least used of the three cache types, uses are often limited to information that will be accessed several times within the same request, usually by more than area of code.&lt;br /&gt;
Cached information is stored in memory by default.&lt;br /&gt;
&lt;br /&gt;
==== Cache types and multiple-server systems ====&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The same applies to session cache, unless you use a &#039;sticky sessions&#039; mechanism to ensure that within a session, users always access the same front-end server.&lt;br /&gt;
&lt;br /&gt;
===Cache backends===&lt;br /&gt;
Cache backends are where data actually gets stored. These include things like the file system, php session, Memcached, and memory.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default just file system, php session, and memory are used within Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
We don&#039;t require that a site has access to any other systems such a Memcached. Instead that is something you are responsible for installing and configuring yourself.&amp;lt;br /&amp;gt;&lt;br /&gt;
When cache backends are mentioned think of systems outside of Moodle that can be used to store data. The MongoDB server, the Memcache server and similiar &amp;quot;server&amp;quot; applications.&lt;br /&gt;
&lt;br /&gt;
===Cache stores===&lt;br /&gt;
Cache stores are a plugin type within Moodle. They facilitate connecting Moodle to the cache backends discussed above.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle ships with the three defaults mentioned above as well as Memcache, Memcached, and MongoDB.&amp;lt;br /&amp;gt;&lt;br /&gt;
You can find other cache store plugins in the [https://moodle.org/plugins/browse.php?list=category&amp;amp;id=48 plugins database].&amp;lt;br /&amp;gt;&lt;br /&gt;
The code for these is located within cache/stores in your Moodle directory root.&lt;br /&gt;
&lt;br /&gt;
Within Moodle you can configure as many cache stores as your architecture requires. If you have several Memcache servers for instance you can create an cache store instance for each.&amp;lt;br /&amp;gt;&lt;br /&gt;
Moodle by default contains three cache store instances that gets when you&#039;ve made no other configuration.&lt;br /&gt;
* A file store instance is created which gets used for all application caches. It stores its data in your moodledata directory.&lt;br /&gt;
* A session store instance is created which gets used for all session caches. It stores its data in the PHP session, which by default is stored if your database.&lt;br /&gt;
* A static memory store instance is created which gets used for all request cache types. Data exists in memory for just the lifetime of a request.&lt;br /&gt;
&lt;br /&gt;
===Caches: what happens in code===&lt;br /&gt;
Caches are created in code and are used by the developer to store data they see a need to cache.&amp;lt;br /&amp;gt;&lt;br /&gt;
Lets keep this section nice and short because perhaps you are not a developer. There is one very important point you must know about.&amp;lt;br /&amp;gt;&lt;br /&gt;
The developer does not get any say in where the data gets cached. They must specify the following information when creating a cache to use.&lt;br /&gt;
# The type of cache they require.&lt;br /&gt;
# The area of code this cache will belong to (the API if you will).&lt;br /&gt;
# The name of the cache, something they make up to describe in one word what the cache stores.&lt;br /&gt;
&lt;br /&gt;
There are several optional requirements and settings they can specify as well, but don&#039;t worry about that at this point.&amp;lt;br /&amp;gt;&lt;br /&gt;
The important point is that they can&#039;t choose which cache backend to use, they can only choose the type of cache they want from the three detailed above.&lt;br /&gt;
&lt;br /&gt;
===How it ties together===&lt;br /&gt;
&lt;br /&gt;
This is best described in relation to roles played in an organisation.&lt;br /&gt;
&lt;br /&gt;
# The system administrator installs the cache backends you wish to use. Memcache, XCache, APC and so on.&amp;lt;br /&amp;gt;Moodle doesn&#039;t know about these, they are outside of Moodle&#039;s scope and purely the responsibility of your system administrator.&lt;br /&gt;
# The Moodle administrator creates a cache store instance in Moodle for each backend the site will make use of.&amp;lt;br /&amp;gt;There can be one or more cache stores instances for each backend. Some backends like Memcached have settings to create separated spaces within one backend.&lt;br /&gt;
# The developer has created caches in code and is using them to store data.&amp;lt;br /&amp;gt;He doesn&#039;t know anything about how you will use your caches, he just creates a &amp;quot;cache&amp;quot; and tells Moodle what type it is best for it.&lt;br /&gt;
# The Moodle administrator creates a mapping between a cache store instance and a cache.&amp;lt;br /&amp;gt;That mapping tells Moodle to use the backend you specify to store the data the developer wants cached.&lt;br /&gt;
&lt;br /&gt;
In addition to that you can take things further still.&lt;br /&gt;
* You can map many caches to a single cache store instance.&lt;br /&gt;
* You can map multiple cache store instances to a single cache with priority (primary ... final)&lt;br /&gt;
* You can map a cache store instance to be the default store used for all caches of a specific type that don&#039;t otherwise have specific mappings.&lt;br /&gt;
&lt;br /&gt;
If this is the first time you are reading about the Moodle Universal Cache this probably sounds pretty complex but don&#039;t worry it will be discussed in better detail as we work through how to configure the caching in Moodle.&lt;br /&gt;
&lt;br /&gt;
==Advanced concepts==&lt;br /&gt;
These concepts are things that most sites will not need to know or concern themselves about.&lt;br /&gt;
&lt;br /&gt;
You should only start looking here if you are looking to maximise performance on large sites running over clustered services with shared cache backends, or on multi-site architecure again where information is being shared between sites.&lt;br /&gt;
&lt;br /&gt;
===Locking===&lt;br /&gt;
&lt;br /&gt;
The idea of locking is nothing new, it is the process of controlling access in order to avoid concurrency issues.&lt;br /&gt;
&lt;br /&gt;
MUC has a second type of plugin, a cache lock plugin that gets used when caches require it. To date no caches have required it, a cache by nature is volatlie and any information that is absolutely mission critical should be a more permanent data store likely the database.&amp;lt;br /&amp;gt;&lt;br /&gt;
None the less there is a locking system that cache definitions can require within their options and that will be applied when interacting with a cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Sharing===&lt;br /&gt;
&lt;br /&gt;
Every bit of data that gets stored within a cache has a calculated unique key associated with it.&amp;lt;br /&amp;gt;&lt;br /&gt;
By default part of that key is the site identifier making any content stored in the cache specific to the site that stored it. For most sites this is exactly what you want.&amp;lt;br /&amp;gt;&lt;br /&gt;
However in some situations its beneficial to allow mutiple sites, or somehow linked sites to share cached data.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course not all caches can be shared, however some certainly can and by sharing you can further reduce load and increase performance by maximising resource use.&lt;br /&gt;
&lt;br /&gt;
This is an advanced feature, if you choose to configure sharing please do so carefully.&lt;br /&gt;
&lt;br /&gt;
To make use of sharing you need to first configure identical cache store instances in the sites you want to share information, and then on each site set the sharing for the cache to the same value.&lt;br /&gt;
&lt;br /&gt;
; Sites with the same site ID : This is the default, it allows for sites with the same site ID to share cached information. It is the most restrictive but is going to work for all caches. All other options carry an element of risk in that you have to ensure the information in the cache is applicable to all sites that will be accessing it.&lt;br /&gt;
; Sites running the same version : All sites accessing the backend that have the same Moodle version can share the information this cache has stored in the cache store.&lt;br /&gt;
; Custom key : For this you manually enter a key to use for sharing. You must then enter the exact same key into the other sites you want to share information.&lt;br /&gt;
; Everyone : The cached data is accessible to all other sites accessing the data. This option puts the ball entirely in the Moodle administrators court.&lt;br /&gt;
&lt;br /&gt;
As an example if you had several Moodle sites all the same version running on server with APC installed you could decide to map the language cache to the APC store and configure sharing for all sites running the same version.&amp;lt;br /&amp;gt;&lt;br /&gt;
The language cache for sites on the same version is safe to share, it is used on practically every page, and APC is extremely fast. These three points may result in a nice wee performance boost for your sites.&lt;br /&gt;
&lt;br /&gt;
==The cache configuration screen==&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen is your one stop shop for configuring caching in Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
It gives you an overview of how caching is currently configured for your site and it provides links to all of the actions you can perform to configure caching to your specific needs.&lt;br /&gt;
&lt;br /&gt;
===Accessing the cache configuration screen===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-01-configuration-screen.png|thumb|500px|The cache configuration screen in Moodle 2.6]]&lt;br /&gt;
&lt;br /&gt;
The cache configuration screen can only be accessed by users with the &#039;&#039;moodle/site:config&#039;&#039; capability. By default this is only admins.&amp;lt;br /&amp;gt;&lt;br /&gt;
Once logged in the configuration screen can be found in the Settings block under &#039;&#039;&#039;Site Administration &amp;gt; Plugins &amp;gt; Caching &amp;gt; Configuration&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Installed cache stores===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-02-installed-cache-stores.png|thumb|500px|Installed cache stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is showing you a list of cache store plugins that you have installed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For each plugin you can quickly see whether it is ready to be used (any php requirements have been met), how many store instances already exist on this site, the cache types that this store can be used for, what features it supports (advanced) and any actions you can perform relating to this store.&lt;br /&gt;
&lt;br /&gt;
Often the only action available is to create a new store instance.&amp;lt;br /&amp;gt;&lt;br /&gt;
Most stores support having multiple instances, however not all as you will see that that the session cache and static request cache do not. For those two stores it does not make sense to have multiple instances.&lt;br /&gt;
&lt;br /&gt;
===Configured store instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-03-configured-store-instances.png|thumb|500px|Configured store instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
Here you get a list of the cache store instances on this site.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : The name given to this cache store instance when it is created so that you can recognise it. It can be anything you want and is only used so that you can identify the store instance.&lt;br /&gt;
; &#039;&#039;&#039;Plugin&#039;&#039;&#039; : The cache store plugin of which this is an instance of.&lt;br /&gt;
; &#039;&#039;&#039;Ready&#039;&#039;&#039; : A tick gets shown when all PHP requirements have been met as well as any connection or set-up requirements have been verified.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The number of caches this store instance has been mapped to explicitly. Does not include any uses through default mappings (discussed below).&lt;br /&gt;
; &#039;&#039;&#039;Modes&#039;&#039;&#039; : The modes that this cache store instance can serve.&lt;br /&gt;
; &#039;&#039;&#039;Supports&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The features supported by this cache store instance.&lt;br /&gt;
; &#039;&#039;&#039;Locking mechanism&#039;&#039;&#039; : &#039;&#039;Advanced&#039;&#039;. The locking mechanism this cache store instance will make use of. We&#039;ve not discussed this yet, but read on and you&#039;ll find information on it.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed against this cache store instance.&lt;br /&gt;
&lt;br /&gt;
===Known cache definitions===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-04-known-cache-definitions.png|thumb|500px|Known cache definitions screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is a list of all the caches within Moodle that have a definition.&amp;lt;br /&amp;gt;&lt;br /&gt;
The idea of a cache definition hasn&#039;t been discussed here. It is something controlled by the developer. When they create a cache they can do so in two ways, the first is by creating a cache definition. This is essentially telling Moodle about the cache they&#039;ve created. The second way is to create an Adhoc cache. Developers are always encouraged to use the first method. Only caches with a definition can be mapped and further configured by the admin. Adhoc caches will make use of default settings only.&amp;lt;br /&amp;gt;&lt;br /&gt;
Typically Adhoc caches are only permitted in situations where the cache is small and configuring it beyond defaults would provide no benefit to administrators. Really its like saying you the administrator doesn&#039;t need to concern yourself with it.&lt;br /&gt;
&lt;br /&gt;
For each cache shown here you get the following information:&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Definition&#039;&#039;&#039; : A concise description of this cache.&lt;br /&gt;
; &#039;&#039;&#039;Mode&#039;&#039;&#039; : The cache type this cache is designed for.&lt;br /&gt;
; &#039;&#039;&#039;Component&#039;&#039;&#039; : The code component the cache is associated with.&lt;br /&gt;
; &#039;&#039;&#039;Area&#039;&#039;&#039; : The area of code this cache is serving within the component.&lt;br /&gt;
; &#039;&#039;&#039;Store mappings&#039;&#039;&#039; : The store or stores that will be used for this cache.&lt;br /&gt;
; &#039;&#039;&#039;Sharing&#039;&#039;&#039; : How is sharing configured for this site.&lt;br /&gt;
; &#039;&#039;&#039;Actions&#039;&#039;&#039; : Any actions that can be performed on the cache. Typically you can edit the cache store instance mappings, edit sharing, and purge the cache.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also find at the bottom of this table a link title &amp;quot;Rescan definitions&amp;quot;. Clicking this link will cause Moodle to go off an check all core components, and installed plugins looking for changes in the cache definitions.&amp;lt;br /&amp;gt;&lt;br /&gt;
This happens by default during upgrade, and if a new cache definition is encountered. However should you find yourself looking for a cache that isn&#039;t there this may be worth a try.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is also handy for developers as it allows them to quickly apply changes when working with caches. Its useful when tweaking cache definitions to find what works best.&lt;br /&gt;
&lt;br /&gt;
===Summary of cache lock instances===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-05-summary-of-cache-lock-instances.png|thumb|500px|Summary of cache lock instances screenshot]]&lt;br /&gt;
&lt;br /&gt;
As mentioned above cache locking is an advanced concept in MUC.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table here shows information on the configured locking mechanisms available to MUC. By default just a single locking mechanism is available, file locking.&lt;br /&gt;
At present there are no caches that make use of this and as such I won&#039;t discuss it further here.&lt;br /&gt;
&lt;br /&gt;
===Stores used when no mapping is present===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-06-stores-used-when-no-mapping-is-present.png|thumb|500px|Mapping of default stores screenshot]]&lt;br /&gt;
&lt;br /&gt;
This table quickly shows which cache store instances are going to be used for cache types if there are specific mappings in place.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of simply this shows the default cache store instances.&lt;br /&gt;
&lt;br /&gt;
At the bottom you will notice there is a link &amp;quot;Edit mappings&amp;quot; that takes you to a page where you can configure this.&lt;br /&gt;
&lt;br /&gt;
==Adding cache store instances==&lt;br /&gt;
&lt;br /&gt;
The default configuration is going to work for all sites, however you may be able to improve you sites performance by making use of various caching backends and techniques. The first thing you are going to want to do is add cache store instances configured to connect to/use the cache backends you&#039;ve set up.&lt;br /&gt;
&lt;br /&gt;
===File cache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-07-add-file-cache-store.png|thumb|300px|Adding a file cache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
When on the cache configuration screen within the &#039;&#039;Installed cache stores&#039;&#039; table you should be able to see the File cache plugin, click &#039;&#039;`Add instance`&#039;&#039; to start the process of adding a file cache store instance.&lt;br /&gt;
&lt;br /&gt;
When creating a file cache there is in fact only one required param, the store name. The store name is used to identify the file store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
It can be anything you want, but we would advice making it something that describes you intended use of the file store.&lt;br /&gt;
&lt;br /&gt;
The following properties can also be specified, customising where the file cache will be located, and how it operates.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Cache path&#039;&#039;&#039; : Allows you to specify a directory to use when storing cache data on the file system. Of course the user the webserver is running as must have read/write access to this directory. By default (blank) the Moodledata directory will be used.&lt;br /&gt;
; &#039;&#039;&#039;Auto create directory&#039;&#039;&#039; : If enabled when the cache is initialised if the specified directory does not exist Moodle will create it. If this is specified and the directory does not exist the the cache will be deemed not ready and will not be used.&lt;br /&gt;
; &#039;&#039;&#039;Single directory store&#039;&#039;&#039; : By default the file store will create a subdirectory structure to store data in. The first 3 characters of the data key will be used as a directory. This is useful in avoiding file system limits it the file system has a maximum number of files per directory. By enabling this option the file cache will not use subdirectories for storage of data. This leads to a flat structure but one that is more likely hit file system limits. Use with care.&lt;br /&gt;
; &#039;&#039;&#039;Prescan directory&#039;&#039;&#039; : One of the features the file cache provides is to prescan the storage directory when the cache is first used. This leads to faster checks of files at the expense of an in-depth read.&lt;br /&gt;
&lt;br /&gt;
The file cache store is the default store used for application caches and by default the moodledata directory gets used for the cache.&lt;br /&gt;
File access can be a taxing resource in times of increased load and the following are some ideas about configuring alternative file stores in order to improve performance.&lt;br /&gt;
&lt;br /&gt;
First up is there a faster file system available for use on your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
Perhaps you&#039;ve an SSD installed but are not using it for your moodledata directory because space is a premium.&amp;lt;br /&amp;gt;&lt;br /&gt;
You should consider creating a directory or small partition on your SSD and creating a file store to use that instead of your Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
Next you&#039;ve not got a faster drive available for use, but you do have plenty of free space.&amp;lt;br /&amp;gt;&lt;br /&gt;
Something that may be worth giving a shot would be to create a small partition on the drive you&#039;ve got installed that uses a performance orientated file system.&amp;lt;br /&amp;gt;&lt;br /&gt;
Many linux installations these days for example use EXT4, a nice file system but one that has overheads due to the likes of journalling.&amp;lt;br /&amp;gt;&lt;br /&gt;
Creating a partition and using a file system that has been optimised for performance may give you that little boost you are looking for. Remember caches are designed to be volatile and choosing a file system for a cache is different decision to choosing a file system for your server.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally if you&#039;re ready to go to lengths and have an abundance of memory on your server you could consider creating a ramdisk/tmpfs and pointing a file store at that.&lt;br /&gt;
Purely based in memory, it is volatile exactly like the cache is, and file system performance just isn&#039;t going to get much better than this.&amp;lt;br /&amp;gt;&lt;br /&gt;
Of course you will be limited in space and you are essentially taking that resource away from your server.&lt;br /&gt;
&lt;br /&gt;
Please remember with all of these ideas that they are just ideas.&amp;lt;br /&amp;gt;&lt;br /&gt;
What ever you choose - test, test, test, be sure of the decision you make.&lt;br /&gt;
&lt;br /&gt;
===Memcache===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-08-add-memcache-store.png|thumb|300px|Add Memcache store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Before you can add a Memcache store instance you must first have a Memcached server you can access and have the Memcache php extension installed and enabled on your web server.&lt;br /&gt;
&lt;br /&gt;
Like the file store you must provide a the store name. It is used to identify the store instance in the configuration interface and must be unique to the site.&amp;lt;br /&amp;gt;&lt;br /&gt;
For a Memcache store you must also enter the Memcache server, or servers you wish it to make use of.&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally you can also specify a key prefix to use. What you enter here will prefixed to all keys before accessing the server and can be used to effectively partition the Memcache space in a recognisable way. This can be handy if you have a management tool for you Memcached server that you use to inspect what is stored there.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-09-add-memcached-store.png|thumb|300px|Add Memcached store screenshot]]&lt;br /&gt;
&lt;br /&gt;
Like the Memcache store you must first have a Memcached server you can access and have the Memcached php extension installed and enabled on your server.&lt;br /&gt;
&lt;br /&gt;
Also like the Memcache store there are two required parameters in configuring a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : It is used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Servers&#039;&#039;&#039; : The servers you wish this cache store use. See below for details.&lt;br /&gt;
&lt;br /&gt;
Servers should be added one per line and each line can contain 1 to 3 properties separated by colons.&lt;br /&gt;
# The URL or IP address of the server (required)&lt;br /&gt;
# The port the server is listening on (optional)&lt;br /&gt;
# The weight to give this server (optional)&lt;br /&gt;
&lt;br /&gt;
For example, if you had two Memcached instances running on your server, one configured for the default port, and one configured for 11212 you would use the following:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
127.0.0.1&lt;br /&gt;
127.0.0.1:11212&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are also several optional parameters you can set when creating a Memcached store.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Use compression&#039;&#039;&#039; : Defaults to true, but can be disabled if you wish.&lt;br /&gt;
; &#039;&#039;&#039;Use serialiser&#039;&#039;&#039; : Allows your to select which serialiser gets used when communicating with the Memcache server. By default the Memcached extension and PHP only provide one serialised, however there is a couple of others available for installation if you go looking for them. One for example is the igbinary found at https://github.com/igbinary/igbinary.&lt;br /&gt;
; &#039;&#039;&#039;Prefix key&#039;&#039;&#039; : Allows you to set some characters that will be prefixed to all keys before interacting with the server.&lt;br /&gt;
; &#039;&#039;&#039;Hash method&#039;&#039;&#039; : The hash method provided by the Memcached extension is used by default here. However you can select to use an alternative if you wish. http://www.php.net/manual/en/memcached.constants.php provides a little information on the options available. Please note if you wish to you can also override the default hash function PHP uses within your php.ini.&lt;br /&gt;
; &#039;&#039;&#039;Buffer writes&#039;&#039;&#039; : Disabled by default, and for good reason. Turning on buffered writes will minimise interaction with the Memcached server by buffering io operations. The downside to this is that on a system with any concurrency there is a good chance multiple requests will end up generating the data because no one had pushed it to the Memcached server when they first requested it. Enabling this can be advantageous for caches that are only accessed in capability controlled areas for example where multiple interaction is taking a toll on network resources or such. But that is definitely on the extreme tweaking end of the scale.&lt;br /&gt;
&lt;br /&gt;
===MongoDB===&lt;br /&gt;
&lt;br /&gt;
[[Image:26-10-add-mongodb-store.png|thumb|300px|Add MongoDB store screenshot]]&lt;br /&gt;
&lt;br /&gt;
MongoDB is an open source document orientated NoSQL database. Check out their website www.mogodb.org for more information.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Store name&#039;&#039;&#039; : Used to identify the store instance in the configuration interface and must be unique to the site.&lt;br /&gt;
; &#039;&#039;&#039;Server&#039;&#039;&#039; : This is the connection string for the server you want to use. Multiple servers can be specified using a comma-separated list.&lt;br /&gt;
; &#039;&#039;&#039;Database&#039;&#039;&#039; : The name of the database to make use of.&lt;br /&gt;
; &#039;&#039;&#039;Username&#039;&#039;&#039; : The username to use when making a connection.&lt;br /&gt;
; &#039;&#039;&#039;Password&#039;&#039;&#039; : The password of the user being used for the connection.&lt;br /&gt;
; &#039;&#039;&#039;Replica set&#039;&#039;&#039; : The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.&lt;br /&gt;
; &#039;&#039;&#039;Use&#039;&#039;&#039; : If enabled the usesafe option will be used during insert, get, and remove operations. If you&#039;ve specified a replica set this will be forced on anyway.&lt;br /&gt;
; &#039;&#039;&#039;Use safe value&#039;&#039;&#039; : You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.&lt;br /&gt;
; &#039;&#039;&#039;Use extended keys&#039;&#039;&#039; : If enabled full key sets will be used when working with the plugin. This isn&#039;t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.&lt;br /&gt;
&lt;br /&gt;
==Mapping a cache to a store instance==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-11-store-mapping.png|thumb|300px|Cache definition store mapping screenshot]]&lt;br /&gt;
&lt;br /&gt;
Mapping a store instance to a cache tells Moodle to use that store instance when the cache is interacted with. This allows the Moodle administrator to control where information gets stored and to most importantly optimise performance of your site by making the most of the resources available to your site.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Known cache definitions&#039;&#039; table and within it find the cache you&#039;d like to map.&lt;br /&gt;
In the actions column you should see a link to&#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
The screen you are presented allows you to map one or more cache store instances to be used by this cache.&lt;br /&gt;
&lt;br /&gt;
If no stores are mapped for the cache then the default stores are used. Have a look at the section below for information on changing the default stores.&lt;br /&gt;
&lt;br /&gt;
If a single store instance is mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from the cache&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the store. If the store has it it gives it to the cache, and the cache gives it to Moodle so that it can use the data. If the store doesn&#039;t have it the a fail is returned and Moodle will have to generate the data and will most likely then send it to the cache.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, and the cache will give it to the cache store.&lt;br /&gt;
&lt;br /&gt;
If multiple store instances are mapped to the cache the following occurs:&lt;br /&gt;
; &#039;&#039;Getting data from a store&#039;&#039; : Moodle asks the cache to get the data. The cache attempts to get it from the first store. If the first store has it then it returns the data to the cache and the cache returns it to Moodle. If the first store doesn&#039;t have the data then it attempts to get the data from the second store. If the second store has it it returns it to the first store that then stores it itself before returning it to the cache. If it doesn&#039;t then the next store is used. This continue until either the data is found or there are no more stores to check.&lt;br /&gt;
; &#039;&#039;Storing data in the cache&#039;&#039; : Moodle will ask the cache to store some data, the cache will give it to every mapped cache store for storage.&lt;br /&gt;
&lt;br /&gt;
The main advantage to assigning multiple stores is that you can introduce cache redundancy. Of course this introduces an overhead so it should only be used when actually required.&lt;br /&gt;
The following is an example of when mapping multiple stores can provide an advantage:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Imagine if you will that you have have a web server that has a Moodle site as well as other sites. You also have a Memcache server that is used by several sites including Moodle.&amp;lt;br /&amp;gt;&lt;br /&gt;
Memcache is a limited size cache, that when full and requested to store more information frees space by dropping least used cache entries.&lt;br /&gt;
You want to use Memcache for your Moodle site because it is fast, however you are aware that it may introduce more cache misses because it is a heavily used Memcache server.&lt;br /&gt;
To get around this you map two stores to caches you wish to use Memcache.&lt;br /&gt;
You make Memcache the primary store, and you make the default file store the final cache store.&lt;br /&gt;
By doing this you&#039;ve created redundancy, when something is requested Moodle first tries to get it from Memcache (the fastest store) and if its not there it proceeds to check the file cache.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just a couple more points of interest:&lt;br /&gt;
&lt;br /&gt;
* Mapping multiple caches will introduce overhead, the more caches mapped the more overhead.&lt;br /&gt;
* Consider the cache stores you are mapping to, if data remains there once set then there is no point mapping any further stores after it. This technique is primarily valuable in situations where data is not guaranteed to remain after being set.&lt;br /&gt;
* Always test your configuration. Enable the display of performance information and then watch which stores get used when interacting with Moodle in such a way as to trigger the cache.&lt;br /&gt;
&lt;br /&gt;
==Setting the stores that get used when no mapping is present==&lt;br /&gt;
&lt;br /&gt;
[[Image:26-12-default-store-mapping.png|thumb|300px|Setting which stores get used when no mapping is present screenshot]]&lt;br /&gt;
&lt;br /&gt;
This is really setting the default stores that get used for a cache type when there is not a specific mapping that has been made for it.&lt;br /&gt;
&lt;br /&gt;
To set a mapping first browse to the cache configuration screen.&amp;lt;br /&amp;gt;&lt;br /&gt;
Proceed to find the &#039;&#039;Stores used when no mapping is present&#039;&#039; table.&amp;lt;br /&amp;gt;&lt;br /&gt;
After the table you will find a link &#039;&#039;&#039;Edit mappings&#039;&#039;&#039;, click this.&lt;br /&gt;
&lt;br /&gt;
On the screen you are presented with you can select one store for each cache type to use when a cache of the corresponding type gets initialised and there is not an explicit mapping for it.&lt;br /&gt;
&lt;br /&gt;
Note that on this interface the drop downs only contain store instances that are suitable for mapping to the type.&lt;br /&gt;
Not all instances will necessarily be shown. If you have a store instance you don&#039;t see then it is not suitable for &#039;&#039;&#039;ALL&#039;&#039;&#039; the cache definitions that exist.&amp;lt;br /&amp;gt;&lt;br /&gt;
You will not be able to make that store instance the default, you will instead need to map it explicitly to each cache you want/can use it for.&lt;br /&gt;
&lt;br /&gt;
==Configuring caching for your site==&lt;br /&gt;
&lt;br /&gt;
This is where it really gets tricky, and unfortunately there is no step by step guide to this.&amp;lt;br /&amp;gt;&lt;br /&gt;
How caching can be best configured for a site comes down entirely to the site in question and the resources available to it.&lt;br /&gt;
&lt;br /&gt;
What can be offered is some tips and tricks to get you thinking about things and to perhaps introduce ideas that will help you along the way.&amp;lt;br /&amp;gt;&lt;br /&gt;
If yu are reading this document and you&#039;ve learnt a thing or two about configuring caching on your site share your learnings by adding to the points here.&lt;br /&gt;
&lt;br /&gt;
* Plan it. It&#039;s a complex thing. Understand your site, understand your system, and really think how users will be using it all.&lt;br /&gt;
* If you&#039;ve got a small site the gains aren&#039;t likely to be significant, if you&#039;ve got a large site getting this right can lead to a substantial boost in performance.&lt;br /&gt;
* When looking at cache backends really research the advantages and disadvantages of each. Keep your site in mind when thinking about them. Depending upon your site you may find that no one cache backend is going to meet the entire needs of your site and that you will benefit from having a couple of backends at your disposal.&lt;br /&gt;
* Things aren&#039;t usually as simple as installing a cache backend and then using it. Pay attention to configuration and try to optimise it for your system. Test it separately and have an understanding of its performance before tell Moodle about it. The cache allows you to shift load off the database and reduce page request processing.&amp;lt;br /&amp;gt;If for instance you have Memcache installed but your connection has not been optimised for it you may well find yourself in a losing situation before you even tell Moodle about the Memcache server.&lt;br /&gt;
* When considering your default store instances keep in mind that they must operate with data sets of varying sizes and frequency. For a large site really your best bet is to look at each cache definition and map it to a store that is best suited for the data it includes and the frequency of access.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Again when mapping store instances to caches really think about the cache you are mapping and make a decision based upon what you understand of your site and what you know about the cache.&amp;lt;br /&amp;gt;Cache definitions have been documented [[User:Sam_Hemelryk/Cache definitions]].&lt;br /&gt;
* Test your configuration. If you can stress test it even better! If you turn on performance information Moodle will also print cache access information at the bottom of the screen. You can use this to visually check the cache is being used as you expect, and it will give you an indication of where misses etc are occurring.&lt;br /&gt;
* Keep an eye on your backend. Moodle doesn&#039;t provide a means of monitoring a cache backend and that is certainly something you should keep an eye on. Memcache for instance drops least used data when full to make room for new entries. APC on the other hand stops accepting data when full. Both will impact your performance if full and you&#039;re going to encounter misses. However APC when full is horrible, but it is much faster.&lt;br /&gt;
&lt;br /&gt;
==Other performance testing==&lt;br /&gt;
&lt;br /&gt;
Two links that might be useful to anyone considering testing performance on their own servers:&lt;br /&gt;
&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/12/moodle-performance-testing-how-much-more-horsepower-do-each-new-versions-of-moodle-require/ Moodle performance testing: how much more horsepower do each new versions of Moodle require?]&lt;br /&gt;
* [http://www.iteachwithmoodle.com/2012/10/11/how-to-stress-test-your-moodle-server-using-loadstorm/ How to load test your Moodle server using Loadstorm]&lt;br /&gt;
&lt;br /&gt;
==Other performance advice for load-balanced web servers==&lt;br /&gt;
&lt;br /&gt;
# In Moodle 2.4 onwards with load-balanced web servers, don&#039;t use the default caching option that stores the data in moodledata on a shared network drive.   Use memcached instead.   See Tim Hunt&#039;s article on http://tjhunt.blogspot.de/2013/05/performance-testing-moodle.html&lt;br /&gt;
# In Moodle 2.6 onwards make sure you set $CFG-&amp;gt;localcachedir to some local directory in config.php (for each node).  This will speed up some of the disk caching that happens outside of MUC, such as themes, javascript, libraries etc.&lt;br /&gt;
&lt;br /&gt;
==More information==&lt;br /&gt;
* [[:dev:User:Sam Hemelryk/Cache definitions]] Information on the cache definitions found within Moodle.&lt;br /&gt;
* [[:dev:Cache API]] Details of the Cache API.&lt;br /&gt;
* [[:dev:Cache API - Quick reference]] A short, code focused page of on the Cache API.&lt;br /&gt;
* [[:dev:The Moodle Universal Cache (MUC)]] The original cache specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cache related forum discussions that may help in understanding MUC:&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=217195 MUC is here, now what?] &lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=226123 Status of MUC?]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=222250 Putting cachedir on local disks in cluster]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=232122 moodle cachestore_file]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other:&lt;br /&gt;
* [http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs. 2.5.1 performance and MUC APC cache store] blog post by Justin Filip&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[de:Caching]]&lt;br /&gt;
[[es:Cacheando]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=112833</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=112833"/>
		<updated>2014-05-29T22:43:48Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Memcached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Session Handling&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
Memcached session driver is the fastest driver, it requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodles in one server.&lt;br /&gt;
* If memcached extension &amp;lt;= 2.1.0 the locking works differently from other drivers, the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d))&lt;br /&gt;
&lt;br /&gt;
===Files===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=112832</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=112832"/>
		<updated>2014-05-29T22:43:09Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Memcached */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Session Handling&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached===&lt;br /&gt;
Memcached session driver is the fastest driver, it requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodles in one server.&lt;br /&gt;
* If memcached extension &amp;lt;= 2.1.0 the locking works differently from other drivers, the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d))&lt;br /&gt;
&lt;br /&gt;
===Files===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=90078</id>
		<title>Användare:Sam Hemelryk</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=90078"/>
		<updated>2011-09-23T02:47:09Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Replaced content with &amp;quot;Hi, I maintain my profile on the dev wiki.
You can find it here:

https://docs.moodle.org/dev/User:Sam_Hemelryk&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi, I maintain my profile on the dev wiki.&lt;br /&gt;
You can find it here:&lt;br /&gt;
&lt;br /&gt;
https://docs.moodle.org/dev/User:Sam_Hemelryk&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=90077</id>
		<title>Användare:Sam Hemelryk/My Moodle Git workflow</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=90077"/>
		<updated>2011-09-23T02:30:50Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Replaced content with &amp;quot;Hi, this doc has previously existed in a couple of locations and has now been consolidated to just one location.
You can now find it here:

https://docs.moodle.org/dev/User:Sa...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi, this doc has previously existed in a couple of locations and has now been consolidated to just one location.&lt;br /&gt;
You can now find it here:&lt;br /&gt;
&lt;br /&gt;
https://docs.moodle.org/dev/User:Sam_Hemelryk/My_Moodle_Git_workflow&lt;br /&gt;
&lt;br /&gt;
PLEASE DO NOT EDIT THIS PAGE, feel free to edit the linked page above.&lt;br /&gt;
&lt;br /&gt;
Cheers&lt;br /&gt;
Sam&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83288</id>
		<title>Themes 2.0 adding courses and categories to the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83288"/>
		<updated>2011-05-06T03:17:56Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* A word of warning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt;&lt;br /&gt;
The reason for writing this tutorial is simply that this seems to be a request that is being made over and over again.&lt;br /&gt;
&lt;br /&gt;
==Before we get started==&lt;br /&gt;
Please please please make sure you are familiar with the other Themes 2.0 tutorials before attempting this tutorial.&lt;br /&gt;
&lt;br /&gt;
In particular I would recommend being familiar with the following documents and tutorials as I&#039;m going to move through this tutorial at a fast pace.&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
&lt;br /&gt;
Providing you are familiar with the above you should manage just fine with this tutorial and if you ever get stuck don&#039;t forget to ask in the theme&#039;s forums, there is always someone around who can help.&lt;br /&gt;
&lt;br /&gt;
===Two words of warning===&lt;br /&gt;
&#039;&#039;&#039;First&#039;&#039;&#039; Just a quick warning here, this tutorial adds all categories and courses to the navigation, on a site with a large number of categories and/or courses this will be a performance hit. I would strongly suggest that if you are looking to implement something such as this on a large site that you talk to your system admin and/or resident developer about setting up a shared cache and caching the result of the get_course_category_tree method... it is a technical task but doing so will improve the performance of this extension on a large site.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Second&#039;&#039;&#039; If you have categories nested 2 or more deep then there is a chance that you will run into display problems with the custom menu on some themes... not too much you can do about it but if you encounter it with a core theme and you fix it perhaps you would be kind enough to create an issue in our bug tracker and share the fix. That&#039;d being said this is only a hunch I have all of the theme&#039;s may be fine :)&lt;br /&gt;
&lt;br /&gt;
==Laying the ground work==&lt;br /&gt;
Alright I don&#039;t want this tutorial to drag out so get ready. For this tutorial I am just going to extend the standard theme, I&#039;m going to make absolutely no changes to the design and layout of the theme or the custom menu I am ONLY going to add a list of courses and categories to it.&lt;br /&gt;
&lt;br /&gt;
So to begin with within your Moodle themes directory create a new directory coursecategorymenu in which I want you to create three files, the first config.php which is obviously required, the second renderers.php as we are going to achieve this by overriding a renderer, and the third the English language file for this theme.&lt;br /&gt;
&lt;br /&gt;
You should end up with:&lt;br /&gt;
&lt;br /&gt;
* moodle/theme/coursecategorymenu&lt;br /&gt;
* moodle/theme/coursecategorymenu/config.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/renderers.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&lt;br /&gt;
&lt;br /&gt;
==config.php==&lt;br /&gt;
Obviously because all I want to base this theme off the standard theme and only override a renderer the config.php file is going to be VERY basic, so much so that I&#039;m not going to go into details about it, as you&#039;ve read the recommended tutorials you will already be completely familiar with everything it is doing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==renderers.php==&lt;br /&gt;
This is of course where the magic is going to happen.&lt;br /&gt;
&lt;br /&gt;
In my case I want to add a branch to the end of the custom menu titled &#039;&#039;Courses&#039;&#039; and then I want to add the category and course structure to that branch.&lt;br /&gt;
&lt;br /&gt;
So like the [[Development:Themes 2.0 extending the custom menu|extending the custom menu]] tutorial I will be overriding the core renderer and I will also be overriding the render_custom_menu_method.&lt;br /&gt;
&lt;br /&gt;
So the code for this:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that is identical to the starting code for the extending custom menu tutorial.&lt;br /&gt;
&lt;br /&gt;
The difference comes in the code that we are going to populate it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So lets work through this code line by line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This we need to do because we are going to use part of the course API, in particular a function called &#039;&#039;get_course_category_tree()&#039;&#039; that we&#039;ll look at shortly.&lt;br /&gt;
The function we want to use exists within the course lib file and in order to be sure its always available we need to include this file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line adds the &#039;&#039;Courses&#039;&#039; branch to the custom menu into which we will add the category and course structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line is the main one to note, here we are calling a Moodle function that will return us a category and course tree, because all courses need to be within a category the initial return is an array of categories, each category in the array will have the properties of the category as well as two additional properties, the first property &#039;&#039;&#039;categories&#039;&#039;&#039; is an array containing all of this categories sub categories, and the second property &#039;&#039;&#039;courses&#039;&#039;&#039; is also an array containing all of the courses within this category.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now these lines of code deal with the initial array of categories returned by the &#039;&#039;get_course_category_tree&#039;&#039; function.&lt;br /&gt;
&lt;br /&gt;
In this case we iterate of the initial categories and for each one we call a method of the renderer &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039; now those of you who are clued in will realise that this method doesn&#039;t exist yet... and you are correct - we need to write this method which is what we will look at next.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a heads up the reason that we need to write another method is because we need a method that we can call recursivily as there are potentially infinite category branches all contains sub categories and courses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final line of code simply calls the original render_custom_menu method now that we have extended the custom menu as we want.&lt;br /&gt;
&lt;br /&gt;
Now that we have looked at the render_custom_menu lets write the function we just talked about &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This function as discussed above is special in that we intend to call it recursively, that means we want to call it once for EVERY category that exists in the tree. We will need to give it the categories parent menu item as well as the category object we want added.&lt;br /&gt;
&lt;br /&gt;
Lets look at the code for this method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
    if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
        foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
        foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
            $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ok so that doesn&#039;t look too bad, as you&#039;ve already read the extending custom menu tutorial you will be able to spot some of the things it is doing, none the less lets walk through the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    .....&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First up the function definition, this function is going to be private because only we need it and it is going to take two arguments, the first $parent has to be a custom_menu_item, the second $category has to be the category object.&lt;br /&gt;
&lt;br /&gt;
The objective of this method is to add a category node to the custom menu, in regards to our arguments we want to add $category as a child of $parent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line looks very familiar, here we are adding a node for the category to the $parent, we are also collecting the newly added node as $branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
    foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
        $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now this code is responsible for add the sub categories of this category to the menu as well, first we need to check that the categories property isn&#039;t empty (if it is there is nothing to add).&lt;br /&gt;
Assuming there are sub categories we need go through each of them and call this method on them so that they get added to the custom menu as well.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is called recursion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
    foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
        $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This code is very similar to the above code except that we are looking at the courses within this category.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also note that this bit of code doesn&#039;t call add_category_to_custommenu recursivily, it doesn&#039;t need to as courses are the last bit we want to display on the menu within the category.&lt;br /&gt;
&lt;br /&gt;
And that is it, time to tidy up and we&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
All of the code is written now there is only last thing to do in order to tidy up however and that is to add the &#039;&#039;courses&#039;&#039; string that we used earlier... did you spot it?&lt;br /&gt;
&lt;br /&gt;
This is of course very easy, open up &#039;&#039;&#039;moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&#039;&#039;&#039; and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we&#039;re done. If you now browse to your site and change to the new theme you should see the Courses branch at the end of your custom menu that contains all of the categories, sub categories and courses for your site.&lt;br /&gt;
&lt;br /&gt;
==Full source==&lt;br /&gt;
===config.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===renderers.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        &lt;br /&gt;
        require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
        &lt;br /&gt;
        $categorytree = get_course_category_tree();&lt;br /&gt;
        foreach ($categorytree as $category) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
        $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
        if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
            foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
                $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
            foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
                $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===lang/en/theme_coursecategorymenu.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83287</id>
		<title>Themes 2.0 adding courses and categories to the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83287"/>
		<updated>2011-05-06T03:11:50Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Before we get started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt;&lt;br /&gt;
The reason for writing this tutorial is simply that this seems to be a request that is being made over and over again.&lt;br /&gt;
&lt;br /&gt;
==Before we get started==&lt;br /&gt;
Please please please make sure you are familiar with the other Themes 2.0 tutorials before attempting this tutorial.&lt;br /&gt;
&lt;br /&gt;
In particular I would recommend being familiar with the following documents and tutorials as I&#039;m going to move through this tutorial at a fast pace.&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
&lt;br /&gt;
Providing you are familiar with the above you should manage just fine with this tutorial and if you ever get stuck don&#039;t forget to ask in the theme&#039;s forums, there is always someone around who can help.&lt;br /&gt;
&lt;br /&gt;
===A word of warning===&lt;br /&gt;
Just a quick warning here, this tutorial adds all categories and courses to the navigation, on a site with a large number of categories and/or courses this will be a performance hit. I would strongly suggest that if you are looking to implement something such as this on a large site that you talk to your system admin and/or resident developer about setting up a shared cache and caching the result of the get_course_category_tree method... it is a technical task but doing so will improve the performance of this extension on a large site.&lt;br /&gt;
&lt;br /&gt;
==Laying the ground work==&lt;br /&gt;
Alright I don&#039;t want this tutorial to drag out so get ready. For this tutorial I am just going to extend the standard theme, I&#039;m going to make absolutely no changes to the design and layout of the theme or the custom menu I am ONLY going to add a list of courses and categories to it.&lt;br /&gt;
&lt;br /&gt;
So to begin with within your Moodle themes directory create a new directory coursecategorymenu in which I want you to create three files, the first config.php which is obviously required, the second renderers.php as we are going to achieve this by overriding a renderer, and the third the English language file for this theme.&lt;br /&gt;
&lt;br /&gt;
You should end up with:&lt;br /&gt;
&lt;br /&gt;
* moodle/theme/coursecategorymenu&lt;br /&gt;
* moodle/theme/coursecategorymenu/config.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/renderers.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&lt;br /&gt;
&lt;br /&gt;
==config.php==&lt;br /&gt;
Obviously because all I want to base this theme off the standard theme and only override a renderer the config.php file is going to be VERY basic, so much so that I&#039;m not going to go into details about it, as you&#039;ve read the recommended tutorials you will already be completely familiar with everything it is doing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==renderers.php==&lt;br /&gt;
This is of course where the magic is going to happen.&lt;br /&gt;
&lt;br /&gt;
In my case I want to add a branch to the end of the custom menu titled &#039;&#039;Courses&#039;&#039; and then I want to add the category and course structure to that branch.&lt;br /&gt;
&lt;br /&gt;
So like the [[Development:Themes 2.0 extending the custom menu|extending the custom menu]] tutorial I will be overriding the core renderer and I will also be overriding the render_custom_menu_method.&lt;br /&gt;
&lt;br /&gt;
So the code for this:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that is identical to the starting code for the extending custom menu tutorial.&lt;br /&gt;
&lt;br /&gt;
The difference comes in the code that we are going to populate it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So lets work through this code line by line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This we need to do because we are going to use part of the course API, in particular a function called &#039;&#039;get_course_category_tree()&#039;&#039; that we&#039;ll look at shortly.&lt;br /&gt;
The function we want to use exists within the course lib file and in order to be sure its always available we need to include this file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line adds the &#039;&#039;Courses&#039;&#039; branch to the custom menu into which we will add the category and course structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line is the main one to note, here we are calling a Moodle function that will return us a category and course tree, because all courses need to be within a category the initial return is an array of categories, each category in the array will have the properties of the category as well as two additional properties, the first property &#039;&#039;&#039;categories&#039;&#039;&#039; is an array containing all of this categories sub categories, and the second property &#039;&#039;&#039;courses&#039;&#039;&#039; is also an array containing all of the courses within this category.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now these lines of code deal with the initial array of categories returned by the &#039;&#039;get_course_category_tree&#039;&#039; function.&lt;br /&gt;
&lt;br /&gt;
In this case we iterate of the initial categories and for each one we call a method of the renderer &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039; now those of you who are clued in will realise that this method doesn&#039;t exist yet... and you are correct - we need to write this method which is what we will look at next.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a heads up the reason that we need to write another method is because we need a method that we can call recursivily as there are potentially infinite category branches all contains sub categories and courses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final line of code simply calls the original render_custom_menu method now that we have extended the custom menu as we want.&lt;br /&gt;
&lt;br /&gt;
Now that we have looked at the render_custom_menu lets write the function we just talked about &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This function as discussed above is special in that we intend to call it recursively, that means we want to call it once for EVERY category that exists in the tree. We will need to give it the categories parent menu item as well as the category object we want added.&lt;br /&gt;
&lt;br /&gt;
Lets look at the code for this method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
    if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
        foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
        foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
            $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ok so that doesn&#039;t look too bad, as you&#039;ve already read the extending custom menu tutorial you will be able to spot some of the things it is doing, none the less lets walk through the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    .....&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First up the function definition, this function is going to be private because only we need it and it is going to take two arguments, the first $parent has to be a custom_menu_item, the second $category has to be the category object.&lt;br /&gt;
&lt;br /&gt;
The objective of this method is to add a category node to the custom menu, in regards to our arguments we want to add $category as a child of $parent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line looks very familiar, here we are adding a node for the category to the $parent, we are also collecting the newly added node as $branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
    foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
        $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now this code is responsible for add the sub categories of this category to the menu as well, first we need to check that the categories property isn&#039;t empty (if it is there is nothing to add).&lt;br /&gt;
Assuming there are sub categories we need go through each of them and call this method on them so that they get added to the custom menu as well.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is called recursion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
    foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
        $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This code is very similar to the above code except that we are looking at the courses within this category.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also note that this bit of code doesn&#039;t call add_category_to_custommenu recursivily, it doesn&#039;t need to as courses are the last bit we want to display on the menu within the category.&lt;br /&gt;
&lt;br /&gt;
And that is it, time to tidy up and we&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
All of the code is written now there is only last thing to do in order to tidy up however and that is to add the &#039;&#039;courses&#039;&#039; string that we used earlier... did you spot it?&lt;br /&gt;
&lt;br /&gt;
This is of course very easy, open up &#039;&#039;&#039;moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&#039;&#039;&#039; and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we&#039;re done. If you now browse to your site and change to the new theme you should see the Courses branch at the end of your custom menu that contains all of the categories, sub categories and courses for your site.&lt;br /&gt;
&lt;br /&gt;
==Full source==&lt;br /&gt;
===config.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===renderers.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        &lt;br /&gt;
        require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
        &lt;br /&gt;
        $categorytree = get_course_category_tree();&lt;br /&gt;
        foreach ($categorytree as $category) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
        $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
        if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
            foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
                $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
            foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
                $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===lang/en/theme_coursecategorymenu.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=83286</id>
		<title>Användare:Sam Hemelryk</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=83286"/>
		<updated>2011-05-06T03:03:21Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I am a senior developer at Moodle and have been with the project since the June 2009.&lt;br /&gt;
&lt;br /&gt;
For those interested I have written a tutorial on my Moodle development process with Git: [[User:Sam_Hemelryk/My_Moodle_Git_workflow]]&lt;br /&gt;
&lt;br /&gt;
A short list of helpful documents I have created:&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]] - A quick step by step guide to creating your first theme.&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]] - A tutorial on creating a custom renderer and changing the HTML Moodle produces.&lt;br /&gt;
* [[Development:Themes 2.0 How to use images within your theme]] - Explains how to use and override images within your theme.&lt;br /&gt;
* [[Development:Themes 2.0 adding a settings page]] - Looks at how to add a setting page making your theme easily customisable.&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]] - Customising the custom menu.&lt;br /&gt;
* [[Development:Themes 2.0 adding courses and categories to the custom menu]] - Extending the custom menu further adding all categories + courses&lt;br /&gt;
* [[Development:Themes 2.0 how to make the dock horizontal]] - Modifying the dock to make it horizontal.&lt;br /&gt;
* [[Development:Themes 2.0 adding upgrade code]]&lt;br /&gt;
* [[Development:Styling and customising the dock]] - How to style and customise the dock.&lt;br /&gt;
* [[Development:Using jQuery with Moodle 2.0]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83285</id>
		<title>Themes 2.0 adding courses and categories to the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83285"/>
		<updated>2011-05-06T03:02:43Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt;&lt;br /&gt;
The reason for writing this tutorial is simply that this seems to be a request that is being made over and over again.&lt;br /&gt;
&lt;br /&gt;
==Before we get started==&lt;br /&gt;
Please please please make sure you are familiar with the other Themes 2.0 tutorials before attempting this tutorial.&lt;br /&gt;
&lt;br /&gt;
In particular I would recommend being familiar with the following documents and tutorials as I&#039;m going to move through this tutorial at a fast pace.&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
&lt;br /&gt;
Providing you are familiar with the above you should manage just fine with this tutorial and if you ever get stuck don&#039;t forget to ask in the theme&#039;s forums, there is always someone around who can help.&lt;br /&gt;
&lt;br /&gt;
==Laying the ground work==&lt;br /&gt;
Alright I don&#039;t want this tutorial to drag out so get ready. For this tutorial I am just going to extend the standard theme, I&#039;m going to make absolutely no changes to the design and layout of the theme or the custom menu I am ONLY going to add a list of courses and categories to it.&lt;br /&gt;
&lt;br /&gt;
So to begin with within your Moodle themes directory create a new directory coursecategorymenu in which I want you to create three files, the first config.php which is obviously required, the second renderers.php as we are going to achieve this by overriding a renderer, and the third the English language file for this theme.&lt;br /&gt;
&lt;br /&gt;
You should end up with:&lt;br /&gt;
&lt;br /&gt;
* moodle/theme/coursecategorymenu&lt;br /&gt;
* moodle/theme/coursecategorymenu/config.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/renderers.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&lt;br /&gt;
&lt;br /&gt;
==config.php==&lt;br /&gt;
Obviously because all I want to base this theme off the standard theme and only override a renderer the config.php file is going to be VERY basic, so much so that I&#039;m not going to go into details about it, as you&#039;ve read the recommended tutorials you will already be completely familiar with everything it is doing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==renderers.php==&lt;br /&gt;
This is of course where the magic is going to happen.&lt;br /&gt;
&lt;br /&gt;
In my case I want to add a branch to the end of the custom menu titled &#039;&#039;Courses&#039;&#039; and then I want to add the category and course structure to that branch.&lt;br /&gt;
&lt;br /&gt;
So like the [[Development:Themes 2.0 extending the custom menu|extending the custom menu]] tutorial I will be overriding the core renderer and I will also be overriding the render_custom_menu_method.&lt;br /&gt;
&lt;br /&gt;
So the code for this:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that is identical to the starting code for the extending custom menu tutorial.&lt;br /&gt;
&lt;br /&gt;
The difference comes in the code that we are going to populate it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So lets work through this code line by line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This we need to do because we are going to use part of the course API, in particular a function called &#039;&#039;get_course_category_tree()&#039;&#039; that we&#039;ll look at shortly.&lt;br /&gt;
The function we want to use exists within the course lib file and in order to be sure its always available we need to include this file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line adds the &#039;&#039;Courses&#039;&#039; branch to the custom menu into which we will add the category and course structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line is the main one to note, here we are calling a Moodle function that will return us a category and course tree, because all courses need to be within a category the initial return is an array of categories, each category in the array will have the properties of the category as well as two additional properties, the first property &#039;&#039;&#039;categories&#039;&#039;&#039; is an array containing all of this categories sub categories, and the second property &#039;&#039;&#039;courses&#039;&#039;&#039; is also an array containing all of the courses within this category.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now these lines of code deal with the initial array of categories returned by the &#039;&#039;get_course_category_tree&#039;&#039; function.&lt;br /&gt;
&lt;br /&gt;
In this case we iterate of the initial categories and for each one we call a method of the renderer &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039; now those of you who are clued in will realise that this method doesn&#039;t exist yet... and you are correct - we need to write this method which is what we will look at next.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a heads up the reason that we need to write another method is because we need a method that we can call recursivily as there are potentially infinite category branches all contains sub categories and courses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final line of code simply calls the original render_custom_menu method now that we have extended the custom menu as we want.&lt;br /&gt;
&lt;br /&gt;
Now that we have looked at the render_custom_menu lets write the function we just talked about &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This function as discussed above is special in that we intend to call it recursively, that means we want to call it once for EVERY category that exists in the tree. We will need to give it the categories parent menu item as well as the category object we want added.&lt;br /&gt;
&lt;br /&gt;
Lets look at the code for this method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
    if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
        foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
        foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
            $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ok so that doesn&#039;t look too bad, as you&#039;ve already read the extending custom menu tutorial you will be able to spot some of the things it is doing, none the less lets walk through the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    .....&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First up the function definition, this function is going to be private because only we need it and it is going to take two arguments, the first $parent has to be a custom_menu_item, the second $category has to be the category object.&lt;br /&gt;
&lt;br /&gt;
The objective of this method is to add a category node to the custom menu, in regards to our arguments we want to add $category as a child of $parent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line looks very familiar, here we are adding a node for the category to the $parent, we are also collecting the newly added node as $branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
    foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
        $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now this code is responsible for add the sub categories of this category to the menu as well, first we need to check that the categories property isn&#039;t empty (if it is there is nothing to add).&lt;br /&gt;
Assuming there are sub categories we need go through each of them and call this method on them so that they get added to the custom menu as well.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is called recursion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
    foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
        $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This code is very similar to the above code except that we are looking at the courses within this category.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also note that this bit of code doesn&#039;t call add_category_to_custommenu recursivily, it doesn&#039;t need to as courses are the last bit we want to display on the menu within the category.&lt;br /&gt;
&lt;br /&gt;
And that is it, time to tidy up and we&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
All of the code is written now there is only last thing to do in order to tidy up however and that is to add the &#039;&#039;courses&#039;&#039; string that we used earlier... did you spot it?&lt;br /&gt;
&lt;br /&gt;
This is of course very easy, open up &#039;&#039;&#039;moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&#039;&#039;&#039; and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we&#039;re done. If you now browse to your site and change to the new theme you should see the Courses branch at the end of your custom menu that contains all of the categories, sub categories and courses for your site.&lt;br /&gt;
&lt;br /&gt;
==Full source==&lt;br /&gt;
===config.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===renderers.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        &lt;br /&gt;
        require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
        &lt;br /&gt;
        $categorytree = get_course_category_tree();&lt;br /&gt;
        foreach ($categorytree as $category) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
        $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
        if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
            foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
                $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
            foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
                $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===lang/en/theme_coursecategorymenu.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_extending_the_custom_menu&amp;diff=83284</id>
		<title>Themes 2.0 extending the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_extending_the_custom_menu&amp;diff=83284"/>
		<updated>2011-05-06T03:02:19Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Themes}}{{Moodle 2.0}}This is a quick tutorial that will quickly run you through extending the custom menu by overriding your theme&#039;s renderer.&lt;br /&gt;
&lt;br /&gt;
This tutorial is primarily PHP coding, and ranges from is a moderate to advanced difficulty.&lt;br /&gt;
&lt;br /&gt;
==Before we begin==&lt;br /&gt;
First things first you need to know a little something about the custom menu. As you are undoubtedly aware the custom menu is populated from a specially crafted lines that you enter within the custommenu admin setting on the theme settings page under appearance in the settings block. Once the admin has entered the custom menu items into the setting and saved them the following steps are what they go through in order to be displayed:&lt;br /&gt;
# The theme calls &#039;&#039;&#039;&#039;&#039;$OUTPUT-&amp;gt;custom_menu()&#039;&#039;&#039;&#039;&#039; which is the core_renderers method responsible for producing the custom menu.&lt;br /&gt;
# core_renderer::custom_menu() does the following:&lt;br /&gt;
## Checks to make sure the admin has added custom menu items.&lt;br /&gt;
## Creates a new &#039;&#039;&#039;&#039;&#039;custom_menu&#039;&#039;&#039;&#039;&#039; object. When the custom menu object is created it turns what ever the admin entered into a structured array of information.&lt;br /&gt;
## Calls core_renderer::render_custom_menu and gives it the custom_menu object.&lt;br /&gt;
# core_renderer::render_custom_menu is where the magic happens, it does the following.&lt;br /&gt;
## First it checks to make sure custom menu contains items.&lt;br /&gt;
## Initialises the JavaScript for the custom menu, this is the YUI3 menunode component.&lt;br /&gt;
## Creates the HTML base of the custom menu&lt;br /&gt;
## Then iterates through all of the items and calls the custom menu and passes them to another function that will turn them into HTML correctly.&lt;br /&gt;
&lt;br /&gt;
I&#039;m going to stop there, as there is no need at this point to go into any more detail. Don&#039;t worry if you are a little lost, it will get clearer as we start working through code.&lt;br /&gt;
&lt;br /&gt;
In this tutorial will we look at how to extend the theme&#039;s renderer in two different way.&lt;br /&gt;
# Add a dynamic My Courses branch to the custom menu that will display all of the courses a user is enrolled in.&lt;br /&gt;
# Get the custom menu to fetch strings from the language files rather than just static strings you type, allowing for a translatable custom menu.&lt;br /&gt;
&lt;br /&gt;
Before you start into this tutorial you should have read the following tutorials I have written, or at least have a good knowledge of the the Moodle 2.0 theme engine and Moodle development.&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
&lt;br /&gt;
As this is a quick tutorial I am going to assume you have created a theme, tested it and got it all working, and are already well on your way to becoming a theme guru.&lt;br /&gt;
&lt;br /&gt;
Because the pressure is on to get Moodle 2.0 out the door this will be a quick tutorial, please if you have any questions or need a hand ask in the theme&#039;s forum.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
Alright, as you have already have your theme ready to go preparation is pretty simple, we are going to go through and create (if you haven&#039;t already) the following files:&lt;br /&gt;
* theme/themename/lib.php&lt;br /&gt;
* theme/themename/renderers.php&lt;br /&gt;
* theme/themename/lang/en/themename.php&lt;br /&gt;
&lt;br /&gt;
Next step open up your themes config.php file and add the following configuration option to it (at the bottom):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already got a custom renderer you will already have this line.&lt;br /&gt;
&lt;br /&gt;
And thats it! now we move on to extending the custom menu.&lt;br /&gt;
&lt;br /&gt;
==Adding the My Courses branch==&lt;br /&gt;
So the point of this extension is to add a &#039;&#039;&#039;My Courses&#039;&#039;&#039; branch to the end of the custom menu.&lt;br /&gt;
&lt;br /&gt;
The plan is to have the my courses branch and then within that branch have an entry for every course the user is enrolled in, much the same as the my courses branch of the navigation. &lt;br /&gt;
&lt;br /&gt;
In order to achieve this we need to add some items to the custom menu, the my courses branch and all of the courses within it. We can do this overriding the core_renderers &#039;&#039;&#039;render_custom_menu&#039;&#039;&#039; method, of more accuratly create our own render_custom_menu method that adds our items and then calls the original. Remember we only need to add items, we don&#039;t need to change what is being produced.&lt;br /&gt;
&lt;br /&gt;
So within our renderers.php file add the following code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_themename_core_renderer extends core_renderer {&lt;br /&gt;
&lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So that is pretty simple right?!&lt;br /&gt;
&lt;br /&gt;
Here we are defining our core_renderer which will contain our overridden method &#039;&#039;render_custom_menu&#039;&#039; which we have also defined there.&lt;br /&gt;
Note the definition of the render_custom_menu must be the same as the original, this means it must be &#039;&#039;&#039;protected&#039;&#039;&#039; and it must take one argument &#039;&#039;&#039;custom_menu $menu&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Next step is to write the code for our render_custom_menu method. As stated above we want to add a branch and courses to the end of it which we can do with the following bit of code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mycourses = $this-&amp;gt;page-&amp;gt;navigation-&amp;gt;get(&#039;mycourses&#039;);&lt;br /&gt;
&lt;br /&gt;
if (isloggedin() &amp;amp;&amp;amp; $mycourses &amp;amp;&amp;amp; $mycourses-&amp;gt;has_children()) {&lt;br /&gt;
    $branchlabel = get_string(&#039;mycourses&#039;);&lt;br /&gt;
    $branchurl   = new moodle_url(&#039;/course/index.php&#039;);&lt;br /&gt;
    $branchtitle = $branchlabel;&lt;br /&gt;
    $branchsort  = 10000;&lt;br /&gt;
&lt;br /&gt;
    $branch = $menu-&amp;gt;add($branchlabel, $branchurl, $branchtitle, $branchsort);&lt;br /&gt;
&lt;br /&gt;
    foreach ($mycourses-&amp;gt;children as $coursenode) {&lt;br /&gt;
        $branch-&amp;gt;add($coursenode-&amp;gt;get_content(), $coursenode-&amp;gt;action, $coursenode-&amp;gt;get_title());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So how this all works....&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mycourses = $this-&amp;gt;page-&amp;gt;navigation-&amp;gt;get(&#039;mycourses&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This line is a little bit of smarts, what we are doing is getting the mycourses branch from the navigation. We could make all of the database calls and work it all out ourselves but this will be much better for performance and is easier!&lt;br /&gt;
&lt;br /&gt;
The next line of code is an &#039;&#039;if&#039;&#039; statement that checks three things&lt;br /&gt;
# The user is logged in, you must be logged in to see your courses.&lt;br /&gt;
# That we have a mycourses object, if the user isn&#039;t enrolled in anything they won&#039;t have a mycourses object.&lt;br /&gt;
# The the mycourses object has children, if it exists it should but it is better to be safe than get errors.&lt;br /&gt;
&lt;br /&gt;
Within the if statement we are doing two main things happening, the first is to add the branch to the menu:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branchlabel = get_string(&#039;mycourses&#039;);&lt;br /&gt;
$branchurl   = new moodle_url(&#039;/course/index.php&#039;);&lt;br /&gt;
$branchtitle = $branchlabel;&lt;br /&gt;
$branchsort  = 10000;&lt;br /&gt;
&lt;br /&gt;
$branch = $menu-&amp;gt;add($branchlabel, $branchurl, $branchtitle, $branchsort);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
When adding a new branch we need to give it three things:&lt;br /&gt;
# A label &#039;&#039;&#039;$branchlabel&#039;&#039;&#039;.&lt;br /&gt;
# A URL &#039;&#039;&#039;$branchurl&#039;&#039;&#039;.&lt;br /&gt;
# A title &#039;&#039;&#039;$branchtitle&#039;&#039;&#039; in this case I have just set it to the same as $branchlabel because I am lazy, you can make it anything you want.&lt;br /&gt;
# A sort order &#039;&#039;&#039;$branchsort&#039;&#039;&#039; this just needs to be high enough that it ends up on last place where we want it. Make it small to put it at the front.&lt;br /&gt;
&lt;br /&gt;
The final line of code from above simply adds it to the menu and collects a reference to it so that we can add courses to it.&lt;br /&gt;
&lt;br /&gt;
The second thing being done in the if statement is iterate through all of the courses in the mycourses object and add them to the branch. That is done with the following bit of code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
foreach ($mycourses-&amp;gt;children as $coursenode) {&lt;br /&gt;
    $branch-&amp;gt;add($coursenode-&amp;gt;get_content(), $coursenode-&amp;gt;action, $coursenode-&amp;gt;get_title());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
So here we go through all of the mycourses objects children (which we know will be courses) and for each one we add an item to the branch.&lt;br /&gt;
When adding items here, like above, we need to give it the following:&lt;br /&gt;
# A label &#039;&#039;&#039;$coursenode-&amp;gt;get_content()&#039;&#039;&#039; returns us the text in the navigation node.&lt;br /&gt;
# A url &#039;&#039;&#039;$coursenode-&amp;gt;action&#039;&#039;&#039; which is the URL for the node.&lt;br /&gt;
# A title &#039;&#039;&#039;$coursenode-&amp;gt;get_title()&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In this case we don&#039;t need to set a sort order because the navigation has already ordered them correctly!&lt;br /&gt;
&lt;br /&gt;
So now we are through the if statement and there is only one line of code left:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line of code simply calls the original &#039;&#039;&#039;core_renderer::render_custom_menu&#039;&#039;&#039; method to do all of the remaining work. Because we don&#039;t need to change the display at all we don&#039;t need to redo what it does, we can just use it!.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How easy way that?! it&#039;s all done, if you open you site in your browser and log in the custom menu should now contain a my courses branch (providing you are enrolled in courses).&lt;br /&gt;
&lt;br /&gt;
==Loading labels from language files==&lt;br /&gt;
If you run a site that is available in more than one language &#039;&#039;&#039;and&#039;&#039;&#039; you want to make use of the custom menu then you will probably be very interested in this.&lt;br /&gt;
&lt;br /&gt;
The idea behind this extension is to load the labels and titles that get shown in the custom menu from the theme&#039;s language files rather than having just the fixed strings you type into the admin setting.&lt;br /&gt;
&lt;br /&gt;
In order to achieve this we need to do somehow override the custom_menu_item class so that it loads the strings from the database if they match a special pattern. We can then update the admin setting to use our patter and wallah! things should load from the language files.&lt;br /&gt;
&lt;br /&gt;
What makes this tricky is that we can&#039;t just override the custom_menu_item class, we also need to override the thing that makes create custom_menu_item instances which in this case is the core_renderer::render_custom_menu_item method.&lt;br /&gt;
&lt;br /&gt;
===Overriding the custom_menu_item class===&lt;br /&gt;
Within your themes lib.php file add the following lines of code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class transmuted_custom_menu_item extends custom_menu_item {&lt;br /&gt;
    public function __construct(custom_menu_item $menunode) {&lt;br /&gt;
        // Our code will go here&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
What we have done here is create a overridden custom_menu_item class called &#039;&#039;&#039;transmuted_custom_menu_item&#039;&#039;&#039;.&lt;br /&gt;
Within that class we are overriding the constructor, the constructor will be given the original menu item and we will need to instatiate this object with the properties of the original.&lt;br /&gt;
Once we have instantiated it with the properties of the original we can alter then as we like.&lt;br /&gt;
&lt;br /&gt;
Next we need to write the contents of the &#039;&#039;__construct&#039;&#039; method:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
parent::__construct($menunode-&amp;gt;get_text(), $menunode-&amp;gt;get_url(), $menunode-&amp;gt;get_title(), $menunode-&amp;gt;get_sort_order(), $menunode-&amp;gt;get_parent());&lt;br /&gt;
$this-&amp;gt;children = $menunode-&amp;gt;get_children();&lt;br /&gt;
&lt;br /&gt;
$matches = array();&lt;br /&gt;
if (preg_match(&#039;/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/&#039;, $this-&amp;gt;text, $matches)) {&lt;br /&gt;
    try {&lt;br /&gt;
        $this-&amp;gt;text = get_string($matches[1], &#039;theme_themename&#039;);&lt;br /&gt;
    } catch (Exception $e) {&lt;br /&gt;
        $this-&amp;gt;text = $matches[1];&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$matches = array();&lt;br /&gt;
if (preg_match(&#039;/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/&#039;, $this-&amp;gt;title, $matches)) {&lt;br /&gt;
    try {&lt;br /&gt;
        $this-&amp;gt;title = get_string($matches[1], &#039;theme_themename&#039;);&lt;br /&gt;
    } catch (Exception $e) {&lt;br /&gt;
        $this-&amp;gt;title = $matches[1];&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So there are essentially four things going on here.&lt;br /&gt;
&lt;br /&gt;
Firs we need to populate this object with the properties of the original item. We do this by calling the original constructor with $menunode&#039;s properties as shown below.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
parent::__construct($menunode-&amp;gt;get_text(), $menunode-&amp;gt;get_url(), $menunode-&amp;gt;get_title(), $menunode-&amp;gt;get_sort_order(), $menunode-&amp;gt;get_parent());&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need to copy the properties that arn&#039;t included in the original constructor, in this case there is only one &#039;&#039;&#039;$this-&amp;gt;children&#039;&#039;&#039;. This should be an array of all of this items children (sub items).&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$this-&amp;gt;children = $menunode-&amp;gt;get_children();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that we have all the properties set up we can modify them. In our case we want to check if the items label and title match a special pattern and if they do we want to fetch them from the language file instead.&lt;br /&gt;
The special pattern is &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;[[stringname]]&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039; where stringname is the name of the string that we want to get from the language file.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$matches = array();&lt;br /&gt;
if (preg_match(&#039;/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/&#039;, $this-&amp;gt;text, $matches)) {&lt;br /&gt;
    try {&lt;br /&gt;
        $this-&amp;gt;text = get_string($matches[1], &#039;theme_themename&#039;);&lt;br /&gt;
    } catch (Exception $e) {&lt;br /&gt;
        $this-&amp;gt;text = $matches[1];&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
In the code above we do the following:&lt;br /&gt;
# Create an array $matches which will hold the stringname if the label matches the pattern.&lt;br /&gt;
# We attempt to match the label to the pattern. If it does the $matches array now contains the stringname.&lt;br /&gt;
# If it did match we call get string as shown.&lt;br /&gt;
&lt;br /&gt;
The third and final thing is to do the above again but this time for the title.&lt;br /&gt;
&lt;br /&gt;
With that done our transmutable_custom_menu_item class is complete. Next step is to make use of it.&lt;br /&gt;
&lt;br /&gt;
===Overriding render_custom_menu_item===&lt;br /&gt;
The next step is make use of the transmutable_custom_menu_item class we created previously. &lt;br /&gt;
&lt;br /&gt;
We can do this by overriding the &#039;&#039;&#039;core_renderer::render_custom_menu_item&#039;&#039;&#039; method within our renderers.php file as shown below.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function render_custom_menu_item(custom_menu_item $menunode) {&lt;br /&gt;
    $transmutedmenunode = new transmuted_custom_menu_item($menunode);&lt;br /&gt;
    return parent::render_custom_menu_item($transmutedmenunode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This is pretty simply, essentially we are using our transmuted_custom_menu_item class like a façade to the original custom_menu_item class by creating a new transmuted instance using the original.&lt;br /&gt;
Once we have the transmuted object we can call the original render_custom_menu_item method with it.&lt;br /&gt;
&lt;br /&gt;
And that is it! Congratulations if you got it this far.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is add strings to your themes language file as required!&lt;br /&gt;
&lt;br /&gt;
==Complete source==&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// theme/themename/renderers.php&lt;br /&gt;
&lt;br /&gt;
class theme_themename_core_renderer extends core_renderer {&lt;br /&gt;
&lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        &lt;br /&gt;
        $mycourses = $this-&amp;gt;page-&amp;gt;navigation-&amp;gt;get(&#039;mycourses&#039;);&lt;br /&gt;
&lt;br /&gt;
        if (isloggedin() &amp;amp;&amp;amp; $mycourses &amp;amp;&amp;amp; $mycourses-&amp;gt;has_children()) {&lt;br /&gt;
            $branchlabel = get_string(&#039;mycourses&#039;);&lt;br /&gt;
            $branchurl   = new moodle_url(&#039;/course/index.php&#039;);&lt;br /&gt;
            $branchtitle = $branchlabel;&lt;br /&gt;
            $branchsort  = 10000;&lt;br /&gt;
&lt;br /&gt;
            $branch = $menu-&amp;gt;add($branchlabel, $branchurl, $branchtitle, $branchsort);&lt;br /&gt;
&lt;br /&gt;
            foreach ($mycourses-&amp;gt;children as $coursenode) {&lt;br /&gt;
                $branch-&amp;gt;add($coursenode-&amp;gt;get_content(), $coursenode-&amp;gt;action, $coursenode-&amp;gt;get_title());&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    protected function render_custom_menu_item(custom_menu_item $menunode) {&lt;br /&gt;
        $transmutedmenunode = new transmuted_custom_menu_item($menunode);&lt;br /&gt;
        return parent::render_custom_menu_item($transmutedmenunode);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// theme/themename/lib.php&lt;br /&gt;
&lt;br /&gt;
class transmuted_custom_menu_item extends custom_menu_item {&lt;br /&gt;
    public function __construct(custom_menu_item $menunode) {&lt;br /&gt;
        parent::__construct($menunode-&amp;gt;get_text(), $menunode-&amp;gt;get_url(), $menunode-&amp;gt;get_title(), $menunode-&amp;gt;get_sort_order(), $menunode-&amp;gt;get_parent());&lt;br /&gt;
        $this-&amp;gt;children = $menunode-&amp;gt;get_children();&lt;br /&gt;
&lt;br /&gt;
        $matches = array();&lt;br /&gt;
        if (preg_match(&#039;/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/&#039;, $this-&amp;gt;text, $matches)) {&lt;br /&gt;
            try {&lt;br /&gt;
                $this-&amp;gt;text = get_string($matches[1], &#039;theme_themename&#039;);&lt;br /&gt;
            } catch (Exception $e) {&lt;br /&gt;
                $this-&amp;gt;text = $matches[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        $matches = array();&lt;br /&gt;
        if (preg_match(&#039;/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/&#039;, $this-&amp;gt;title, $matches)) {&lt;br /&gt;
            try {&lt;br /&gt;
                $this-&amp;gt;title = get_string($matches[1], &#039;theme_themename&#039;);&lt;br /&gt;
            } catch (Exception $e) {&lt;br /&gt;
                $this-&amp;gt;title = $matches[1];&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 adding courses and categories to the custom menu]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0&amp;diff=83283</id>
		<title>Themes 2.0</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0&amp;diff=83283"/>
		<updated>2011-05-06T03:01:57Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Themes}}{{Moodle 2.0}}Welcome to the new world of themes within Moodle 2.0!&lt;br /&gt;
&lt;br /&gt;
This document explains how themes work in Moodle and is intended to help you create or modify most themes for Moodle 2.0.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Moodle themes are responsible for much of the &amp;quot;look&amp;quot; of a Moodle site.  They provide the CSS for colours, layouts, fonts and so on, and can also change the structural XHTML code below that.  &lt;br /&gt;
&lt;br /&gt;
A theme can either contain all the definitions (completely stand alone) or it can extend an existing theme with one or more customizations. &lt;br /&gt;
&lt;br /&gt;
Most theme developers use the second method and simply add a few new CSS or layout definitions to their new theme. If a definition or element is not found in the new theme, it looks to the &amp;quot;parent&amp;quot; (or up the hierarchy of themes) to find one.  It an easy way to achieve just about any look you want for a theme.&lt;br /&gt;
&lt;br /&gt;
==What&#039;s new in 2.0==&lt;br /&gt;
&lt;br /&gt;
The theme system was completely redesigned in Moodle 2.0.  Known issues have been addressed and new features have been added to meet community requests.&lt;br /&gt;
&lt;br /&gt;
Unfortunately it was not possible to maintain backward compatibility, so all Moodle 1.x themes need to be recreated for Moodle 2.0.&lt;br /&gt;
&lt;br /&gt;
Major changes include:&lt;br /&gt;
* Clearer and more consistent CSS classes and IDs throughout all pages in Moodle&lt;br /&gt;
* Introduction of layout files (templates) describing overall layout HTML for many different types of pages in Moodle.&lt;br /&gt;
* Introduction of renderers, which produce the smaller &amp;quot;parts&amp;quot; of a HTML page.  Advanced themes can choose to override these too if they choose.&lt;br /&gt;
* Introduction of standard methods for adding Javascript to themes.&lt;br /&gt;
* Easier control over icons and images in Moodle.&lt;br /&gt;
* The old &amp;quot;standard&amp;quot; theme has been split into two themes:&lt;br /&gt;
**&#039;&#039;&#039;base&#039;&#039;&#039; - contains absolutely basic layout, and&lt;br /&gt;
**&#039;&#039;&#039;standard&#039;&#039;&#039; - which adds CSS to the base theme to make it look like the old standard theme.&lt;br /&gt;
* Performance tuning: In normal production mode CSS files are combined into a single optimised file, and both CSS and JavaScript files are minimised to ensure there are no wasted connections or traffic.  Files are heavily cached, but also versioned, so that users never need to clear their caches.&lt;br /&gt;
&lt;br /&gt;
==The structure of a theme==&lt;br /&gt;
&lt;br /&gt;
Some important things to know when building good themes:&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;config.php&#039;&#039;&#039; - this file is required in every theme.  It defines configuration settings and definitions required to make the theme work in Moodle. These include theme, file, region, default region and options. &lt;br /&gt;
# &#039;&#039;&#039;Layouts and layout files&#039;&#039;&#039; -  in config.php there is one definition for each page type (see [[#theme_layouts_table|Appendix A: Theme layouts]] for a list of over 12 types).  Each page type definition tells Moodle which layout file will be used, what block regions this page type should display and so on.  The layout file contains the HTML and the minimum PHP required to display basic structure of pages. (If you know Moodle 1.9, it&#039;s like a combination of header.html and footer.html).&lt;br /&gt;
# &#039;&#039;&#039;The base theme&#039;&#039;&#039; - is not intended to be used for production sites.  It sets up the simplest possible generic layout and includes only CSS essential to that layout &#039;&#039;or&#039;&#039; to Moodle as a whole.  It tries not to make any unnecessary rules and makes as few assumptions as possible.  It&#039;s the perfect base on which to start designing a theme, as there are very few colours, borders, margins, and alignments to override.  You can just start adding what you need.&lt;br /&gt;
&lt;br /&gt;
===Files and folders===&lt;br /&gt;
A theme&#039;s files are placed in a folder with under moodle/theme folder and have subfolders. They are laid out like this:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Directory&lt;br /&gt;
! File&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| /config.php&lt;br /&gt;
| Contains all of the configuration and definitions for each theme&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| /lib.php &lt;br /&gt;
| Contains speciality classes and functions that are used by theme&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| /renderers.php &lt;br /&gt;
| Contains any custom renderers for the theme.&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| /settings.php &lt;br /&gt;
| Contains custom theme settings. These local settings are defined by the theme allowing the theme user to easily alter something about the way it looks or operates. (eg a background colour, or a header image)&lt;br /&gt;
|-&lt;br /&gt;
| /javascript/ &lt;br /&gt;
| &lt;br /&gt;
| All specialty JavaScript files the theme requires should be located in here.&lt;br /&gt;
|-&lt;br /&gt;
| /lang/ &lt;br /&gt;
| &lt;br /&gt;
| Any special language files the theme requires should be located in here.&lt;br /&gt;
|-&lt;br /&gt;
| /layout/ &lt;br /&gt;
| &lt;br /&gt;
| Contains the layout files for the theme.&lt;br /&gt;
|-&lt;br /&gt;
| /pix/ &lt;br /&gt;
| &lt;br /&gt;
| Contains any images the theme makes use of either in CSS or in the layout files.&lt;br /&gt;
|-&lt;br /&gt;
|  /pix&lt;br /&gt;
| /favicon.ico &lt;br /&gt;
| The favicon to display for this theme.&lt;br /&gt;
|-&lt;br /&gt;
| /pix&lt;br /&gt;
| /screenshot.jpg &lt;br /&gt;
| A screenshot of the theme to be displayed in on the theme selection screen.&lt;br /&gt;
|-&lt;br /&gt;
| /style &lt;br /&gt;
| &lt;br /&gt;
| Default location for CSS files.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|/*.css&lt;br /&gt;
|CSS files the theme requires&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
There are also several other places that stylesheets can be included from (see the CSS how and why section below).&lt;br /&gt;
&lt;br /&gt;
==Theme options==&lt;br /&gt;
All theme options are set within the config.php file for the theme.  The settings that are most used are: parents, sheets, layouts, and javascripts. Have a look at the &#039;&#039;&#039;[[#theme_options_table|theme options table]]&#039;&#039;&#039; for a complete list of theme options which include lesser used specialised or advanced settings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Basic theme config example===&lt;br /&gt;
Lets have a look at a basic theme configuration file and the different bits that make it up:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$THEME-&amp;gt;name = &#039;newtheme&#039;;&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;parents = array(&lt;br /&gt;
    &#039;base&#039;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;sheets = array(&lt;br /&gt;
    &#039;admin&#039;,&lt;br /&gt;
    &#039;blocks&#039;,&lt;br /&gt;
    &#039;calendar&#039;,&lt;br /&gt;
    &#039;course&#039;,&lt;br /&gt;
    &#039;grade&#039;,&lt;br /&gt;
    &#039;message&#039;,&lt;br /&gt;
    &#039;question&#039;,&lt;br /&gt;
    &#039;user&#039;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;layouts = array(&lt;br /&gt;
    &#039;base&#039; =&amp;gt; array(&lt;br /&gt;
        &#039;theme&#039; =&amp;gt; &#039;newtheme&#039;,&lt;br /&gt;
        &#039;file&#039; =&amp;gt; &#039;general.php&#039;,&lt;br /&gt;
        &#039;regions&#039; =&amp;gt; array(),&lt;br /&gt;
    ),&lt;br /&gt;
    &#039;standard&#039; =&amp;gt; array(&lt;br /&gt;
        &#039;theme&#039; =&amp;gt; &#039;newtheme&#039;,&lt;br /&gt;
        &#039;file&#039; =&amp;gt; &#039;general.php&#039;,&lt;br /&gt;
        &#039;regions&#039; =&amp;gt; array(&#039;side-pre&#039;, &#039;side-post&#039;),&lt;br /&gt;
        &#039;defaultregion&#039; =&amp;gt; &#039;side-post&#039;,&lt;br /&gt;
    )&lt;br /&gt;
    //.......&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;javascripts_footer = array(&lt;br /&gt;
    &#039;navigation&#039;&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic theme example settings explained===&lt;br /&gt;
First up you will notice everything is added to $THEME. This is the theme&#039;s configuration object, it is created by Moodle using default settings and is then updated by whatever settings you add to it.&lt;br /&gt;
&lt;br /&gt;
The first setting, $THEME-&amp;gt;name is the theme&#039;s name. This should simply be whatever your theme&#039;s name is, most likely whatever you named your theme directory.&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;parents defines the themes that the theme will extend. In this case it is extending only the base theme.&lt;br /&gt;
&lt;br /&gt;
After this is the $THEME-&amp;gt;sheets array containing the names of the CSS stylesheets to include for this theme. Note that it is just the name of the stylesheet and does not contain the directory or the file extension. Moodle assumes that the theme&#039;s stylesheets will be located in the styles directory of the theme and have .css as an extension.&lt;br /&gt;
&lt;br /&gt;
Next we see the $THEME-&amp;gt;layouts definition. In this example, two layouts have been defined to override the layouts from the base theme. For more information see the [[#Layouts|layouts]] section below.&lt;br /&gt;
&lt;br /&gt;
The final setting is to include a JavaScript file, as $THEME-&amp;gt;javascripts_footer. Much like stylesheets, you only need to provide the files name. Moodle will assume it is in your themes JavaScript directory and be a .js file.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;: When you first begin writing themes, make sure you take a look at the configuration files of the other themes that get shipped with Moodle. You will get a good picture of how everything works, and what is going on in a theme, simply by reading it and taking notice of what it is including or excluding.&lt;br /&gt;
&lt;br /&gt;
==CSS==&lt;br /&gt;
===Locations of CSS files===&lt;br /&gt;
First lets look at where CSS can be included from within Moodle:&lt;br /&gt;
; \theme\themename\styles\*.css : This is the default location for all of the stylesheets that are used by a theme and the place which should be used by a theme designer.&lt;br /&gt;
&lt;br /&gt;
New theme developers should note that the order in which CSS files are found and included creates a hierarchy.  This order ensures that the rules, within a theme&#039;s style sheets, take precedence over identical rules in other files that may have been introduced before.  This can both extend another files definitions (see parent array in the config file) and also ensures that the current theme&#039;s CSS rules/definitions have the last say.&lt;br /&gt;
&lt;br /&gt;
There are other locations that can be used (although very rarely) to include CSS in a page. A developer of a php file can manually specify a stylesheet from anywhere within Moodle, like the database. Usually, if code is doing this, it is because there is a non-theme config or plugin setting that contains information requires special CSS information.  As a theme designer you should be aware of, but not have to worry about, these locations of CSS files.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
; {pluginpath}\styles.css e.g. \block\blockname\styles.css or \mod\modname\styles.css : Every plugin can have its own styles.css file. This file should only contain the required CSS rules for the module and should not add anything to the look of the plugin such as colours, font sizes, or margins other than those that are truly required.&amp;lt;br /&amp;gt;Theme specific styles for a plugin should be located within the themes styles directory.&lt;br /&gt;
; {pluginpath}\styles_themename.css : This should only ever be used by plugin developers. It allows them to write CSS that is designed for a specific theme without having to make changes to that theme. You will notice that this is never used within Moodle and is designed to be used only by contributed code.&lt;br /&gt;
&lt;br /&gt;
As theme designers, we will only use the first method of introducing CSS: adding rules to a stylesheet file located in the themes styles directory.&lt;br /&gt;
&lt;br /&gt;
===Moodle&#039;s core CSS organisation===&lt;br /&gt;
The next thing to look at is the organisation of CSS and rules within a theme. Although as a theme designer it is entirely up to you as to how you create and organise your CSS. Please note that within the themes provided in the standard install by Moodle there is a very clear organisation of CSS.&lt;br /&gt;
&lt;br /&gt;
First is the  pagelayout.css file. This contains the CSS required to give the layouts their look and feel.  It doesn&#039;t contain any rules that affect the content generated by Moodle.&lt;br /&gt;
&lt;br /&gt;
Next is the core.css file. If you open up core you will notice that it contains all manner of general (usually simple) rules that don&#039;t relate to a specific section of Moodle but to Moodle as a whole.&lt;br /&gt;
&lt;br /&gt;
There can also be rules that relate to specific sections.  However, this is done only when there are only a handful of rules for that section. These small clusters of rules are grouped together and separated by comments identifying for which section each relates.&lt;br /&gt;
&lt;br /&gt;
Finally there are all the other CSS files, you will notice that there is a file for each section of Moodle that has a significant collection of rules.&lt;br /&gt;
&lt;br /&gt;
:For those who are familiar with Moodle 1.9 theme&#039;s, this organisation will be a big change. In 1.9, CSS was organised by its nature (for example: colours, layout, other).&lt;br /&gt;
&lt;br /&gt;
===How to write effective CSS rules within Moodle===&lt;br /&gt;
In Moodle 2.0, writing good CSS rules is an incredibly important.&lt;br /&gt;
&lt;br /&gt;
Due to performance requirements and browser limitations, all of the CSS files are combined into a single CSS file that gets included every time. This means that rules need to be written in such a way as to minimise the chances of a collision leading to unwanted styles being applied. Whilst writing good CSS is something most designers strive for we have implemented several new body classes and put more emphasis on developers for using classes more appropriately.&lt;br /&gt;
&lt;br /&gt;
====The body tag====&lt;br /&gt;
As of Moodle 2.0 the ID tag that gets applied to the body will always be a representation of the URI. For example if you are looking at a forum posting and the URI is &#039;/mod/forum/view.php&#039; then the body tags ID will be &#039;#page-mod-forum-view&#039;.&lt;br /&gt;
&lt;br /&gt;
As well as the body&#039;s ID attribute the URI is also exploded to form several CSS classes that get added to the body tag, so in the above example &#039;/mod/forum/view&#039; you would end up with the following classes being added to the body tag &#039;.path-mod&#039;, &#039;.path-mod-forum&#039;. Note that &#039;.path-mod-forum-view&#039; is not added as a class, this is intentionally left out to lessen confusion and duplication as rules can relate directly to the page by using the ID and do not require the final class.&lt;br /&gt;
&lt;br /&gt;
The body ID and body classes described above will form the bread and butter for many of the CSS rules you will need to write for your theme, however there are also several other very handy classes that get added to the body tag that will be beneficial to you once you start your journey down the rabbit hole that is themeing. Some of the more interesting classes are listed below.&lt;br /&gt;
&lt;br /&gt;
* If JavaScript is enabled then &#039;jsenabled&#039; will be added as a class to the body tag allowing you to style based on JavaScript being enabled or not.&lt;br /&gt;
* Either &#039;dir-rtl&#039; or &#039;dir-ltr&#039; will be added to the body as a class depending on the direction of the language pack: rtl = right to left, ltr = left to right. This allows you to determine your text-alignment based on language if required.&lt;br /&gt;
* A class will be added to represent the language pack currently in use, by default en_utf8 is used by Moodle and will result in the class &#039;lang-en_utf8&#039; being added to the body tag.&lt;br /&gt;
* The wwwroot for Moodle will also be converted to a class and added to the body tag allowing you to stylise your theme based on the URL through which it was reached. e.g. http://sam.moodle.local/moodle/ will become &#039;.sam-moodle-local—moodle&#039;&lt;br /&gt;
* If the current user is not logged then &#039;.notloggedin&#039; will be added to the body tag.&lt;br /&gt;
&lt;br /&gt;
What does all of this look like in practise? Well using the above example /mod/forum/view.php you would get at least the following body tag:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&amp;lt;body id=”page-mod-forum-view” class=”path-mod path-mod-forum” /&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Writing your rules====&lt;br /&gt;
The best use of body ids and classes and writing selectors will reduce problems.&lt;br /&gt;
&lt;br /&gt;
There are many specific classes used within Moodle. We try to put them everywhere where anyone may want to apply their own styles. It is important to recognise that no one developer can be aware of the all of the class names that have been used all throughout Moodle, let alone within all of the different contributed bits and pieces available for Moodle.  It is up to the theme developer to write good rules and minimise the chances of a collision between rules because in this case good CSS is FAR more effective.&lt;br /&gt;
&lt;br /&gt;
When starting to write rules make sure that you have a good understanding of where you want those rules to be applied, it is a good idea to make the most of the body classes mentioned above.&lt;br /&gt;
If you want to write a rule for a specific page make use of the body tag&#039;s ID, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code css&amp;gt;#page-mod-forum-view .forumpost {border:1px solid orange;)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to write a rule that will be applied all throughout the forum.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code css&amp;gt;.path-mod-forum .forumpost {border:1px solid orange;}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The other very important thing to take into consideration is the structure leading up to the tag you want to style. Browsers apply conflicting styles with priority on the more specific selectors. It can be very beneficial to keep this in mind and write full selectors that rely on the structure of the tags leading to the tag you wish to style.&lt;br /&gt;
&lt;br /&gt;
By making use of body id&#039;s and classes and writing selectors to take into account the leading structure you can greatly minimise the chance of a collision both with Moodle now and in the future.&lt;br /&gt;
&lt;br /&gt;
==Layouts==&lt;br /&gt;
All themes are required to define the layouts they wish to be responsible for as well as create; however, many layout files are required by those layouts. If the theme is overriding another theme then it is a case of deciding which layouts this new theme should override. If the theme is a completely fresh start then you will need to define a layout for each of the different possibilities. For both situations these layouts should be defined within config.php.&lt;br /&gt;
&lt;br /&gt;
It is also important to note that a new theme that will base itself on another theme (overriding it) does not need to define any layouts or use any layout files if there are no changes that it wishes to make to the layouts of the existing theme. The standard theme in Moodle is a good example of this as it extends the base theme simply adding CSS to achieve its look and feel.&lt;br /&gt;
&lt;br /&gt;
So layouts... as mentioned earlier layouts are defined in config.php within $THEME-&amp;gt;layouts. The following is an example of one such layout definition:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$THEME-&amp;gt;layouts = array(&lt;br /&gt;
    // Standard layout with blocks, this is recommended for most pages with general information&lt;br /&gt;
    &#039;standard&#039; =&amp;gt; array(&lt;br /&gt;
        &#039;theme&#039; =&amp;gt; &#039;base&#039;,&lt;br /&gt;
        &#039;file&#039; =&amp;gt; &#039;general.php&#039;,&lt;br /&gt;
        &#039;regions&#039; =&amp;gt; array(&#039;side-pre&#039;, &#039;side-post&#039;),&lt;br /&gt;
        &#039;defaultregion&#039; =&amp;gt; &#039;side-post&#039;&lt;br /&gt;
    )&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The first thing Moodle looks at is the name of the layout, in this case it is `standard` (the array key in PHP), it then looks at the settings for the layout, this is the theme, file, regions, and default region. There are also a couple of other options that can be set by a layout.&lt;br /&gt;
&lt;br /&gt;
; theme : is the theme the layout file exists in. That&#039;s right you can make use of layouts from other installed themes. &#039;&#039;Optional&#039;&#039;&lt;br /&gt;
; file : is the name of the layout file this layout wants to use. &#039;&#039;Required&#039;&#039;&lt;br /&gt;
; regions : is the different block regions (places you can put blocks) within the theme. &#039;&#039;Required&#039;&#039;&lt;br /&gt;
; defaultregion : is the default location when adding new blocks. &#039;&#039;&#039;Required if regions is non-empty, otherwise optional&#039;&#039;&#039;&lt;br /&gt;
; options : an array of layout specific options described in detail below. &#039;&#039;&#039;Optional&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;theme&#039;&#039;&#039; is optional. Normally the the layout file is looked for in the current theme, or, if it is not there, in the parent theme. However, you can use a layout file from any other theme by giving the theme name here.&lt;br /&gt;
&lt;br /&gt;
You can define whatever regions you like. You just need to pick an name for each one. Most themes just use one or both of &#039;&#039;&#039;side_pre&#039;&#039;&#039; and &#039;&#039;&#039;side_post&#039;&#039;&#039;, which is like &#039;left side&#039; and &#039;right side&#039;, except in right to left languages, when they are reversed. If you say in config.php that your the layout provides regions called &#039;fred&#039; and &#039;barney&#039;, then you must call $OUTPUT-&amp;gt;blocks_for_region(&#039;fred&#039;) and $OUTPUT-&amp;gt;blocks_for_region(&#039;barney&#039;) somewhere in the layout file.&lt;br /&gt;
&lt;br /&gt;
The final setting &#039;&#039;&#039;options&#039;&#039;&#039; is a special case that only needs to be set if you want to make use of it. This setting allows the theme designer to specify special options that they would like to create that can be later accessed within the layout file. This allows the theme to make design decisions during the definition and react upon those decisions in what ever layout file is being used.&lt;br /&gt;
&lt;br /&gt;
One such place this has been used is infact within the base theme. If you take a look first at theme/base/config.php you will notice that several layouts specify options &#039;&#039;&#039;nonavbar&#039;&#039;&#039; and &#039;&#039;&#039;nofooter&#039;&#039;&#039; which can both be set to either true or false. Then if we take a look at theme/base/layout/general.php you will spot lines like the following:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$hasnavbar = (empty($PAGE-&amp;gt;layout_options[&#039;nonavbar&#039;]) &amp;amp;&amp;amp; $PAGE-&amp;gt;has_navbar());&lt;br /&gt;
$hasfooter = (empty($PAGE-&amp;gt;layout_options[&#039;nofooter&#039;]));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
............&lt;br /&gt;
&amp;lt;?php if ($hasnavbar) { ?&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;navbar clearfix&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;breadcrumb&amp;quot;&amp;gt;&amp;lt;?php echo $OUTPUT-&amp;gt;navbar(); ?&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;navbutton&amp;quot;&amp;gt; &amp;lt;?php echo $PAGE-&amp;gt;button; ?&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;?php } ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
What you are seeing here is the use of those settings from the layout within the layout file. In this case it is being used to toggle the display of the navigation bar and page footer.&lt;br /&gt;
&lt;br /&gt;
==Layout files==&lt;br /&gt;
A layout file is a file that contains the core HTML structure for a layout including the header, footer, content and block regions.&lt;br /&gt;
For those of you who are familiar with themes in Moodle 1.9 this is simply header.html and footer.html combined.&lt;br /&gt;
Of course it is not all HTML, there are bits of HTML and content that Moodle needs to put into the page, within each layout file this will be done by a couple of VERY simple PHP calls to get bits and pieces including content.&lt;br /&gt;
&lt;br /&gt;
The following is a very simple layout file to illustrate the different bits that make it up:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;doctype() ?&amp;gt;&lt;br /&gt;
&amp;lt;html &amp;lt;?php echo $OUTPUT-&amp;gt;htmlattributes() ?&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;&amp;lt;?php echo $PAGE-&amp;gt;title ?&amp;gt;&amp;lt;/title&amp;gt;&lt;br /&gt;
    &amp;lt;?php echo $OUTPUT-&amp;gt;standard_head_html() ?&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body id=&amp;quot;&amp;lt;?php p($PAGE-&amp;gt;bodyid) ?&amp;gt;&amp;quot; class=&amp;quot;&amp;lt;?php p($PAGE-&amp;gt;bodyclasses) ?&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;standard_top_of_body_html() ?&amp;gt;&lt;br /&gt;
&amp;lt;table id=&amp;quot;page&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;h1 class=&amp;quot;headermain&amp;quot;&amp;gt;&amp;lt;?php echo $PAGE-&amp;gt;heading ?&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
            &amp;lt;div class=&amp;quot;headermenu&amp;quot;&amp;gt;&amp;lt;?php echo $OUTPUT-&amp;gt;login_info(); echo $PAGE-&amp;gt;headingmenu; ?&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;td&amp;gt;&lt;br /&gt;
            &amp;lt;?php echo $OUTPUT-&amp;gt;blocks_for_region(&#039;side-pre&#039;) ?&amp;gt;&lt;br /&gt;
        &amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;td&amp;gt;&lt;br /&gt;
            &amp;lt;?php echo core_renderer::MAIN_CONTENT_TOKEN ?&amp;gt;&lt;br /&gt;
        &amp;lt;/td&amp;gt;&lt;br /&gt;
        &amp;lt;td&amp;gt;&lt;br /&gt;
            &amp;lt;?php echo $OUTPUT-&amp;gt;blocks_for_region(&#039;side-post&#039;) ?&amp;gt;&lt;br /&gt;
        &amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
        &amp;lt;td colspan=&amp;quot;3&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;p class=&amp;quot;helplink&amp;quot;&amp;gt;&amp;lt;?php echo page_doc_link(get_string(&#039;moodledocslink&#039;)) ?&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
            &amp;lt;?php&lt;br /&gt;
            echo $OUTPUT-&amp;gt;login_info();&lt;br /&gt;
            echo $OUTPUT-&amp;gt;home_link();&lt;br /&gt;
            echo $OUTPUT-&amp;gt;standard_footer_html();&lt;br /&gt;
            ?&amp;gt;&lt;br /&gt;
        &amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;standard_end_of_body_html() ?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets assume you know a enough HTML to understand the basic structure above, what you probably don&#039;t understand are the PHP calls so lets look at them.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;doctype() ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This occurs at the VERY top of the page, it must be the first bit of output and is responsible for adding the (X)HTML document type definition to the page. This of course is determined by the settings of the site and is one of the things that the theme designer has no control over.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;html &amp;lt;?php echo $OUTPUT-&amp;gt;htmlattributes() ?&amp;gt;&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we have started writing the opening html tag and have asked Moodle to give us the HTML attributes that should be applied to it. This again is determined by several settings within the actual HTML install.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $PAGE-&amp;gt;title ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This gets us the title for the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;standard_head_html() ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This very important call gets us the standard head HTML that needs to be within the HEAD tag of the page. This is where CSS and JavaScript requirements for the top of the page will be output as well as any special script or style tags.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;body id=&amp;quot;&amp;lt;?php p($PAGE-&amp;gt;bodyid); ?&amp;gt;&amp;quot; class=&amp;quot;&amp;lt;?php p($PAGE-&amp;gt;bodyclasses); ?&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Much like the html tag above we have started writing the body tag and have asked for Moodle to get us the desired ID and classes that should be applied to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;h1 class=&amp;quot;headermain&amp;quot;&amp;gt;&amp;lt;?php echo $PAGE-&amp;gt;heading; ?&amp;gt;&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;headermenu&amp;quot;&amp;gt;&amp;lt;?php echo $OUTPUT-&amp;gt;login_info(); echo $PAGE-&amp;gt;headingmenu; ?&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are creating the header for the page. In this case we want the heading for the page, we want to display the login information which will be the current users username or a link to log in if they are not logged in, and we want the heading menu if there is one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;blocks_for_region(&#039;side-pre&#039;) ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we get the HTML to display the blocks that have been added to the page. In this case we have asked for all blocks that have been added to the area labelled &#039;&#039;side-pre&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo core_renderer::MAIN_CONTENT_TOKEN ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This is one of the most important calls within the file, it determines where the actual content for the page gets inserted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php echo $OUTPUT-&amp;gt;blocks_for_region(&#039;side-post&#039;) ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we get the HTML to display the blocks that have been added to the page. In this case we have asked for all blocks that have been added to the area labelled &#039;&#039;side-post&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo $OUTPUT-&amp;gt;login_info();&lt;br /&gt;
echo $OUTPUT-&amp;gt;home_link();&lt;br /&gt;
echo $OUTPUT-&amp;gt;standard_footer_html();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This final bit of code gets the content for the footer of the page. It gets the login information which is the same as in the header, a home link, and the standard footer HTML which like the standard head HTML contains all of the script and style tags required by the page and requested to go in the footer.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Note&#039;&#039;&#039;&#039;&#039;: Within Moodle 2.0 most of the JavaScript for the page will be included in the footer. This greatly helps reduce the loading time of the page.&lt;br /&gt;
&lt;br /&gt;
When writing layout files think about the different layouts and how the HTML that each makes use of will differ. You will most likely find you do not need a different layout file for each layout, most likely you will be able to reuse the layout files you create across several layouts. You can of course make use of layout options as well to further reduce the number of layout files you need to produce.&lt;br /&gt;
&lt;br /&gt;
Of course as mentioned above if you are customising an existing theme then you may not need to create any layouts or layout files at all.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;$OUTPUT&#039;&#039;&#039; is an instance of the &#039;&#039;&#039;core_renderer&#039;&#039;&#039; class which is defined in lib/outputrenderers.php. Each method is clearly documented there, along with which is appropriate for use within the layout files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;$PAGE&#039;&#039;&#039; is an instance of the &#039;&#039;&#039;moodle_page&#039;&#039;&#039; class defined in lib/pagelib.php. Most of the things you will want to use are the properties that are all documented at the top of the file. If you are not familiar with PHP properties, you access them like $PAGE-&amp;gt;activityname, just like fields of an ordinary PHP object. (However, behind the scenes, some magic is going on, and the value you get is produced by calling a function. Also, you cannot change these values, they are read-only. However, you don&#039;t need to understand all that if you are just using these properties in your theme.)&lt;br /&gt;
&lt;br /&gt;
==Making use of images==&lt;br /&gt;
Right at the start when listing the features of the new themes system one of the features mentioned was the ability to override any of the standard images within Moodle from within your theme. At this point we will look at both how to make use of your own images within your theme, and secondly how to override the images being used by Moodle.&lt;br /&gt;
So first up a bit about images within Moodle,&lt;br /&gt;
&lt;br /&gt;
# Images you want to use within your theme &#039;&#039;&#039;need&#039;&#039;&#039; to be located within your theme&#039;s pix directory.&lt;br /&gt;
# You can use sub directories within the pix directory of your theme.&lt;br /&gt;
# Images used by Moodle&#039;s core are located within the pix directory of Moodle.&lt;br /&gt;
# Modules, blocks and other plugins should also store there images within a pix directory.&lt;br /&gt;
&lt;br /&gt;
So making use of your own images first up. Lets assume you have added two image files to the pix directory of your theme.&lt;br /&gt;
&lt;br /&gt;
* /theme/yourthemename/pix/imageone.jpg&lt;br /&gt;
* /theme/yourthemename/pix/subdir/imagetwo.png&lt;br /&gt;
&lt;br /&gt;
Notice that one image is a JPEG image, and the second is a PNG. Also the second image is in a subdirectory.&lt;br /&gt;
&lt;br /&gt;
The following code snippet illustrates how to make use of your images within HTML, such as if you wanted to use them within a layout file.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;quot;&amp;lt;?php echo $OUTPUT-&amp;gt;pix_url(&#039;imageone&#039;, &#039;theme&#039;);?&amp;gt;&amp;quot; alt=&amp;quot;&amp;quot; /&amp;gt; &lt;br /&gt;
&amp;lt;img src=&amp;quot;&amp;lt;?php echo $OUTPUT-&amp;gt;pix_url(&#039;subdir/imagetwo&#039;, &#039;theme&#039;);?&amp;gt;&amp;quot; alt=&amp;quot;&amp;quot; /&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DO NOT&#039;&#039;&#039; include the image file extension. Moodle will work it out automatically and it will not work if you do include it.&lt;br /&gt;
&lt;br /&gt;
In this case rather than writing out the URL to the image we use a method of Moodle&#039;s output library. Its not too important how that functions works but it is important that we use it as it is what allows images within Moodle to be over-rideable.&lt;br /&gt;
&lt;br /&gt;
The following is how you would use the images from within CSS as background images.&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
.divone {background-image:url([[pix:theme|imageone]]);}&lt;br /&gt;
.divtwo {background-image:url([[pix:theme|subdir/imagetwo]]);}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
If this case we have to use some special notations that Moodle looks for. Whenever Moodle hands out a CSS file it first searches for all &#039;&#039;[[something]]&#039;&#039; tags and replaces them with what is required.&lt;br /&gt;
&lt;br /&gt;
The final thing to notice with both of the cases above is that at no point do we include the images file extension. &lt;br /&gt;
The reason for this leads us into the next topic, how to override images.&lt;br /&gt;
&lt;br /&gt;
From within a theme you can VERY easily override any standard image within Moodle by simply adding the replacement image to the theme&#039;s pix directory in the same sub directory structure as it is in Moodle.&lt;br /&gt;
So for instance we wanted to override the following two images:&lt;br /&gt;
# /pix/moodlelogo.gif&lt;br /&gt;
# /pix/i/user.gif&lt;br /&gt;
We would simply need to add our replacement images to the theme in the following locations&lt;br /&gt;
# /theme/themename/pix/moodlelogo.gif&lt;br /&gt;
# /theme/themename/pix/i/user.gif&lt;br /&gt;
How easy is that!&lt;br /&gt;
&lt;br /&gt;
Now the other very cool thing to mention is that Moodle looks for not just replacements of the same image type (jpg, gif, etc...) but also replacements in any image format. This is why above when working with our images we never specified the images file extension.&lt;br /&gt;
This means that the following would also work:&lt;br /&gt;
# /theme/themename/pix/moodlelogo.png&lt;br /&gt;
# /theme/themename/pix/i/user.bmp&lt;br /&gt;
&lt;br /&gt;
For a more detailed description of how this all works see the page on [[Development:Themes_2.0_How_to_use_images_within_your_theme|using images within your theme]]&lt;br /&gt;
&lt;br /&gt;
==Unobvious Things==&lt;br /&gt;
===Getting Your Theme to Appear Correctly in Theme Selector===&lt;br /&gt;
If you follow the examples on this page to the letter, when you go to the Theme Selector page you may be discouraged to find that your theme does not appear like the other themes do. In fact, instead of your theme&#039;s name, you will see something along the lines of &amp;lt;nowiki&amp;gt;[[pluginname]]&amp;lt;/nowiki&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
To correct this, you must add the /lang/en/theme_THEMENAME.php file, where THEMENAME is the name of the theme folder. Inside that file, add the string &amp;quot;$string[&#039;pluginname&#039;] = &#039;THEMENAME&#039;; &amp;quot;. Make THEMENAME the name of your theme, however you want it displayed in the Theme selector.&lt;br /&gt;
&lt;br /&gt;
The screenshot for the theme should be about 500x400 px.&lt;br /&gt;
&lt;br /&gt;
===Required theme divs===&lt;br /&gt;
&lt;br /&gt;
Some parts of Moodle may rely on particular divs, for example the div with id &#039;page-header&#039;.&lt;br /&gt;
&lt;br /&gt;
Consequently all themes must include at least the divs (with the same ids) that are present in the &#039;base&#039; theme. &lt;br /&gt;
&lt;br /&gt;
Missing out these elements may result in unexpected behaviour within specific modules or other plugins.&lt;br /&gt;
&lt;br /&gt;
==Appendix A==&lt;br /&gt;
===Theme options as of April 28th, 2010===&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot; id=&amp;quot;theme_options_table&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Setting&lt;br /&gt;
! Effect&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;csspostprocess&#039;&#039;&#039;&lt;br /&gt;
|  Allows the user to provide the name of a function that all CSS should be passed to before being delivered.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;editor_sheets&#039;&#039;&#039;&lt;br /&gt;
|  An array of stylesheets to include within the body of the editor.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;enable_dock&#039;&#039;&#039;&lt;br /&gt;
|  If set to true the side dock is enabled for blocks&lt;br /&gt;
|-&lt;br /&gt;
| $THEME-&amp;gt;&#039;&#039;&#039;hidefromselector&#039;&#039;&#039;&lt;br /&gt;
| Used to hide a theme from the theme selector (unless theme designer mode is on). Accepts true or false.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;filter_mediaplugin_colors&#039;&#039;&#039;&lt;br /&gt;
|  Used to control the colours used in the small media player for the filters&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;javascripts&#039;&#039;&#039;&lt;br /&gt;
|  An array containing the names of JavaScript files located in /javascript/ to include in the theme. (gets included in the head)&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;javascripts_footer&#039;&#039;&#039;&lt;br /&gt;
|  As above but will be included in the page footer.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;larrow&#039;&#039;&#039;&lt;br /&gt;
|  Overrides the left arrow image used throughout Moodle&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;layouts&#039;&#039;&#039;&lt;br /&gt;
|  An array setting the layouts for the theme&lt;br /&gt;
|-&lt;br /&gt;
| $THEME-&amp;gt;&#039;&#039;&#039;name&#039;&#039;&#039;&lt;br /&gt;
| Name of the theme. Most likely the name of the directory in which this file resides.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;parents&#039;&#039;&#039;&lt;br /&gt;
|  An array of themes to inherit from&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;parents_exclude_javascripts&#039;&#039;&#039;&lt;br /&gt;
|  An array of JavaScript files NOT to inherit from the themes parents&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;parents_exclude_sheets&#039;&#039;&#039;&lt;br /&gt;
|  An array of stylesheets not to inherit from the themes parents&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;plugins_exclude_sheets&#039;&#039;&#039;&lt;br /&gt;
|  An array of plugin sheets to ignore and not include.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;rarrow&#039;&#039;&#039;&lt;br /&gt;
|  Overrides the right arrow image used throughout Moodle&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;renderfactory&#039;&#039;&#039;&lt;br /&gt;
|  Sets a custom render factory to use with the theme, used when working with custom renderers.&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;resource_mp3player_colors&#039;&#039;&#039;&lt;br /&gt;
|  Controls the colours for the MP3 player&lt;br /&gt;
|-&lt;br /&gt;
|  $THEME-&amp;gt;&#039;&#039;&#039;sheets&#039;&#039;&#039;&lt;br /&gt;
|  An array of stylesheets to include for this theme. Should be located in the theme&#039;s style directory.&lt;br /&gt;
|}&lt;br /&gt;
===The different layouts as of August 17th, 2010===&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot; id=&amp;quot;theme_layouts_table&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Layout&lt;br /&gt;
! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| base&lt;br /&gt;
| Most backwards compatible layout without the blocks - this is the layout used by default.&lt;br /&gt;
|- &lt;br /&gt;
| standard&lt;br /&gt;
| Standard layout with blocks, this is recommended for most pages with general information.&lt;br /&gt;
|- &lt;br /&gt;
| course&lt;br /&gt;
| Main course page.&lt;br /&gt;
|- &lt;br /&gt;
| coursecategory&lt;br /&gt;
| Use for browsing through course categories.&lt;br /&gt;
|- &lt;br /&gt;
| incourse&lt;br /&gt;
| Default layout while browsing a course, typical for modules.&lt;br /&gt;
|- &lt;br /&gt;
| frontpage&lt;br /&gt;
| The site home page.&lt;br /&gt;
|- &lt;br /&gt;
| admin&lt;br /&gt;
| Administration pages and scripts.&lt;br /&gt;
|- &lt;br /&gt;
| mydashboard&lt;br /&gt;
| My dashboard page.&lt;br /&gt;
|- &lt;br /&gt;
| mypublic&lt;br /&gt;
| My public page.&lt;br /&gt;
|- &lt;br /&gt;
| login&lt;br /&gt;
| The login page.&lt;br /&gt;
|-&lt;br /&gt;
| popup&lt;br /&gt;
| Pages that appear in pop-up windows - no navigation, no blocks, no header.&lt;br /&gt;
|-&lt;br /&gt;
| frametop&lt;br /&gt;
| Used for legacy frame layouts only. No blocks and minimal footer.&lt;br /&gt;
|-&lt;br /&gt;
| embedded&lt;br /&gt;
| Embeded pages, like iframe/object embedded in moodleform - it needs as much space as possible&lt;br /&gt;
|-&lt;br /&gt;
| maintenance&lt;br /&gt;
| Used during upgrade and install. This must not have any blocks, and it is good idea if it does not have links to other places - for example there should not be a home link in the footer.&lt;br /&gt;
|-&lt;br /&gt;
| print&lt;br /&gt;
| Used when the page is being displayed specifically for printing.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]] - A quick step by step guide to creating your first theme.&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]] - A tutorial on creating a custom renderer and changing the HTML Moodle produces.&lt;br /&gt;
* [[Development:Themes 2.0 How to use images within your theme]] - Explains how to use and override images within your theme.&lt;br /&gt;
* [[Development:Themes 2.0 adding a settings page]] - Looks at how to add a setting page making your theme easily customisable.&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]] - Customising the custom menu.&lt;br /&gt;
* [[Development:Themes 2.0 adding courses and categories to the custom menu]] - Extending the custom menu further adding all categories + courses&lt;br /&gt;
* [[Development:Themes 2.0 how to make the dock horizontal]] - Modifying the dock to make it horizontal.&lt;br /&gt;
* [[Development:Themes 2.0 adding upgrade code]]&lt;br /&gt;
* [[Development:Styling and customising the dock]] - How to style and customise the dock.&lt;br /&gt;
* [[Development:Theme changes in 2.0]]&lt;br /&gt;
* [[Development:Using jQuery with Moodle 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 how to clone a Moodle 2.0 theme]] &lt;br /&gt;
* [http://www.youtube.com/watch?v=OvaU54uh-qA New themes in Moodle 2.0 video]&lt;br /&gt;
&lt;br /&gt;
[[de:Designs 2.0]]&lt;br /&gt;
[[es:Temas 2.0]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83282</id>
		<title>Themes 2.0 adding courses and categories to the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83282"/>
		<updated>2011-05-06T02:55:54Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* lang/en/theme_ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt;&lt;br /&gt;
The reason for writing this tutorial is simply that this seems to be a request that is being made over and over again.&lt;br /&gt;
&lt;br /&gt;
==Before we get started==&lt;br /&gt;
Please please please make sure you are familiar with the other Themes 2.0 tutorials before attempting this tutorial.&lt;br /&gt;
&lt;br /&gt;
In particular I would recommend being familiar with the following documents and tutorials as I&#039;m going to move through this tutorial at a fast pace.&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
&lt;br /&gt;
Providing you are familiar with the above you should manage just fine with this tutorial and if you ever get stuck don&#039;t forget to ask in the theme&#039;s forums, there is always someone around who can help.&lt;br /&gt;
&lt;br /&gt;
==Laying the ground work==&lt;br /&gt;
Alright I don&#039;t want this tutorial to drag out so get ready. For this tutorial I am just going to extend the standard theme, I&#039;m going to make absolutely no changes to the design and layout of the theme or the custom menu I am ONLY going to add a list of courses and categories to it.&lt;br /&gt;
&lt;br /&gt;
So to begin with within your Moodle themes directory create a new directory coursecategorymenu in which I want you to create three files, the first config.php which is obviously required, the second renderers.php as we are going to achieve this by overriding a renderer, and the third the English language file for this theme.&lt;br /&gt;
&lt;br /&gt;
You should end up with:&lt;br /&gt;
&lt;br /&gt;
* moodle/theme/coursecategorymenu&lt;br /&gt;
* moodle/theme/coursecategorymenu/config.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/renderers.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&lt;br /&gt;
&lt;br /&gt;
==config.php==&lt;br /&gt;
Obviously because all I want to base this theme off the standard theme and only override a renderer the config.php file is going to be VERY basic, so much so that I&#039;m not going to go into details about it, as you&#039;ve read the recommended tutorials you will already be completely familiar with everything it is doing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==renderers.php==&lt;br /&gt;
This is of course where the magic is going to happen.&lt;br /&gt;
&lt;br /&gt;
In my case I want to add a branch to the end of the custom menu titled &#039;&#039;Courses&#039;&#039; and then I want to add the category and course structure to that branch.&lt;br /&gt;
&lt;br /&gt;
So like the [[Development:Themes 2.0 extending the custom menu|extending the custom menu]] tutorial I will be overriding the core renderer and I will also be overriding the render_custom_menu_method.&lt;br /&gt;
&lt;br /&gt;
So the code for this:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that is identical to the starting code for the extending custom menu tutorial.&lt;br /&gt;
&lt;br /&gt;
The difference comes in the code that we are going to populate it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So lets work through this code line by line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This we need to do because we are going to use part of the course API, in particular a function called &#039;&#039;get_course_category_tree()&#039;&#039; that we&#039;ll look at shortly.&lt;br /&gt;
The function we want to use exists within the course lib file and in order to be sure its always available we need to include this file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line adds the &#039;&#039;Courses&#039;&#039; branch to the custom menu into which we will add the category and course structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line is the main one to note, here we are calling a Moodle function that will return us a category and course tree, because all courses need to be within a category the initial return is an array of categories, each category in the array will have the properties of the category as well as two additional properties, the first property &#039;&#039;&#039;categories&#039;&#039;&#039; is an array containing all of this categories sub categories, and the second property &#039;&#039;&#039;courses&#039;&#039;&#039; is also an array containing all of the courses within this category.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now these lines of code deal with the initial array of categories returned by the &#039;&#039;get_course_category_tree&#039;&#039; function.&lt;br /&gt;
&lt;br /&gt;
In this case we iterate of the initial categories and for each one we call a method of the renderer &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039; now those of you who are clued in will realise that this method doesn&#039;t exist yet... and you are correct - we need to write this method which is what we will look at next.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a heads up the reason that we need to write another method is because we need a method that we can call recursivily as there are potentially infinite category branches all contains sub categories and courses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final line of code simply calls the original render_custom_menu method now that we have extended the custom menu as we want.&lt;br /&gt;
&lt;br /&gt;
Now that we have looked at the render_custom_menu lets write the function we just talked about &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This function as discussed above is special in that we intend to call it recursively, that means we want to call it once for EVERY category that exists in the tree. We will need to give it the categories parent menu item as well as the category object we want added.&lt;br /&gt;
&lt;br /&gt;
Lets look at the code for this method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
    if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
        foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
        foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
            $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ok so that doesn&#039;t look too bad, as you&#039;ve already read the extending custom menu tutorial you will be able to spot some of the things it is doing, none the less lets walk through the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    .....&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First up the function definition, this function is going to be private because only we need it and it is going to take two arguments, the first $parent has to be a custom_menu_item, the second $category has to be the category object.&lt;br /&gt;
&lt;br /&gt;
The objective of this method is to add a category node to the custom menu, in regards to our arguments we want to add $category as a child of $parent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line looks very familiar, here we are adding a node for the category to the $parent, we are also collecting the newly added node as $branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
    foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
        $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now this code is responsible for add the sub categories of this category to the menu as well, first we need to check that the categories property isn&#039;t empty (if it is there is nothing to add).&lt;br /&gt;
Assuming there are sub categories we need go through each of them and call this method on them so that they get added to the custom menu as well.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is called recursion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
    foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
        $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This code is very similar to the above code except that we are looking at the courses within this category.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also note that this bit of code doesn&#039;t call add_category_to_custommenu recursivily, it doesn&#039;t need to as courses are the last bit we want to display on the menu within the category.&lt;br /&gt;
&lt;br /&gt;
And that is it, time to tidy up and we&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
All of the code is written now there is only last thing to do in order to tidy up however and that is to add the &#039;&#039;courses&#039;&#039; string that we used earlier... did you spot it?&lt;br /&gt;
&lt;br /&gt;
This is of course very easy, open up &#039;&#039;&#039;moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&#039;&#039;&#039; and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we&#039;re done. If you now browse to your site and change to the new theme you should see the Courses branch at the end of your custom menu that contains all of the categories, sub categories and courses for your site.&lt;br /&gt;
&lt;br /&gt;
==Full source==&lt;br /&gt;
===config.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===renderers.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        &lt;br /&gt;
        require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
        &lt;br /&gt;
        $categorytree = get_course_category_tree();&lt;br /&gt;
        foreach ($categorytree as $category) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
        $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
        if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
            foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
                $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
            foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
                $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===lang/en/theme_coursecategorymenu.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83281</id>
		<title>Themes 2.0 adding courses and categories to the custom menu</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Themes_2.0_adding_courses_and_categories_to_the_custom_menu&amp;diff=83281"/>
		<updated>2011-05-06T02:55:38Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: Created page with &amp;quot;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt; The reason for writing this tutorial is simply that this see...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello this is going to be a very brief tutorial on how to add a courses and categories tree to the custom menu.&amp;lt;br /&amp;gt;&lt;br /&gt;
The reason for writing this tutorial is simply that this seems to be a request that is being made over and over again.&lt;br /&gt;
&lt;br /&gt;
==Before we get started==&lt;br /&gt;
Please please please make sure you are familiar with the other Themes 2.0 tutorials before attempting this tutorial.&lt;br /&gt;
&lt;br /&gt;
In particular I would recommend being familiar with the following documents and tutorials as I&#039;m going to move through this tutorial at a fast pace.&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]]&lt;br /&gt;
&lt;br /&gt;
Providing you are familiar with the above you should manage just fine with this tutorial and if you ever get stuck don&#039;t forget to ask in the theme&#039;s forums, there is always someone around who can help.&lt;br /&gt;
&lt;br /&gt;
==Laying the ground work==&lt;br /&gt;
Alright I don&#039;t want this tutorial to drag out so get ready. For this tutorial I am just going to extend the standard theme, I&#039;m going to make absolutely no changes to the design and layout of the theme or the custom menu I am ONLY going to add a list of courses and categories to it.&lt;br /&gt;
&lt;br /&gt;
So to begin with within your Moodle themes directory create a new directory coursecategorymenu in which I want you to create three files, the first config.php which is obviously required, the second renderers.php as we are going to achieve this by overriding a renderer, and the third the English language file for this theme.&lt;br /&gt;
&lt;br /&gt;
You should end up with:&lt;br /&gt;
&lt;br /&gt;
* moodle/theme/coursecategorymenu&lt;br /&gt;
* moodle/theme/coursecategorymenu/config.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/renderers.php&lt;br /&gt;
* moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&lt;br /&gt;
&lt;br /&gt;
==config.php==&lt;br /&gt;
Obviously because all I want to base this theme off the standard theme and only override a renderer the config.php file is going to be VERY basic, so much so that I&#039;m not going to go into details about it, as you&#039;ve read the recommended tutorials you will already be completely familiar with everything it is doing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==renderers.php==&lt;br /&gt;
This is of course where the magic is going to happen.&lt;br /&gt;
&lt;br /&gt;
In my case I want to add a branch to the end of the custom menu titled &#039;&#039;Courses&#039;&#039; and then I want to add the category and course structure to that branch.&lt;br /&gt;
&lt;br /&gt;
So like the [[Development:Themes 2.0 extending the custom menu|extending the custom menu]] tutorial I will be overriding the core renderer and I will also be overriding the render_custom_menu_method.&lt;br /&gt;
&lt;br /&gt;
So the code for this:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        // Our code will go here shortly&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that is identical to the starting code for the extending custom menu tutorial.&lt;br /&gt;
&lt;br /&gt;
The difference comes in the code that we are going to populate it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So lets work through this code line by line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This we need to do because we are going to use part of the course API, in particular a function called &#039;&#039;get_course_category_tree()&#039;&#039; that we&#039;ll look at shortly.&lt;br /&gt;
The function we want to use exists within the course lib file and in order to be sure its always available we need to include this file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line adds the &#039;&#039;Courses&#039;&#039; branch to the custom menu into which we will add the category and course structure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line is the main one to note, here we are calling a Moodle function that will return us a category and course tree, because all courses need to be within a category the initial return is an array of categories, each category in the array will have the properties of the category as well as two additional properties, the first property &#039;&#039;&#039;categories&#039;&#039;&#039; is an array containing all of this categories sub categories, and the second property &#039;&#039;&#039;courses&#039;&#039;&#039; is also an array containing all of the courses within this category.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$categorytree = get_course_category_tree();&lt;br /&gt;
foreach ($categorytree as $category) {&lt;br /&gt;
    $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now these lines of code deal with the initial array of categories returned by the &#039;&#039;get_course_category_tree&#039;&#039; function.&lt;br /&gt;
&lt;br /&gt;
In this case we iterate of the initial categories and for each one we call a method of the renderer &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039; now those of you who are clued in will realise that this method doesn&#039;t exist yet... and you are correct - we need to write this method which is what we will look at next.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a heads up the reason that we need to write another method is because we need a method that we can call recursivily as there are potentially infinite category branches all contains sub categories and courses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
return parent::render_custom_menu($menu);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The final line of code simply calls the original render_custom_menu method now that we have extended the custom menu as we want.&lt;br /&gt;
&lt;br /&gt;
Now that we have looked at the render_custom_menu lets write the function we just talked about &#039;&#039;&#039;add_category_to_custommenu&#039;&#039;&#039;.&amp;lt;br /&amp;gt;&lt;br /&gt;
This function as discussed above is special in that we intend to call it recursively, that means we want to call it once for EVERY category that exists in the tree. We will need to give it the categories parent menu item as well as the category object we want added.&lt;br /&gt;
&lt;br /&gt;
Lets look at the code for this method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
    if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
        foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
        foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
            $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ok so that doesn&#039;t look too bad, as you&#039;ve already read the extending custom menu tutorial you will be able to spot some of the things it is doing, none the less lets walk through the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
    .....&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First up the function definition, this function is going to be private because only we need it and it is going to take two arguments, the first $parent has to be a custom_menu_item, the second $category has to be the category object.&lt;br /&gt;
&lt;br /&gt;
The objective of this method is to add a category node to the custom menu, in regards to our arguments we want to add $category as a child of $parent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This line looks very familiar, here we are adding a node for the category to the $parent, we are also collecting the newly added node as $branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
    foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
        $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now this code is responsible for add the sub categories of this category to the menu as well, first we need to check that the categories property isn&#039;t empty (if it is there is nothing to add).&lt;br /&gt;
Assuming there are sub categories we need go through each of them and call this method on them so that they get added to the custom menu as well.&amp;lt;br /&amp;gt;&lt;br /&gt;
This is called recursion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
    foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
        $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This code is very similar to the above code except that we are looking at the courses within this category.&amp;lt;br /&amp;gt;&lt;br /&gt;
Also note that this bit of code doesn&#039;t call add_category_to_custommenu recursivily, it doesn&#039;t need to as courses are the last bit we want to display on the menu within the category.&lt;br /&gt;
&lt;br /&gt;
And that is it, time to tidy up and we&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
All of the code is written now there is only last thing to do in order to tidy up however and that is to add the &#039;&#039;courses&#039;&#039; string that we used earlier... did you spot it?&lt;br /&gt;
&lt;br /&gt;
This is of course very easy, open up &#039;&#039;&#039;moodle/theme/coursecategorymenu/lang/en/theme_coursecategorymenu.php&#039;&#039;&#039; and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we&#039;re done. If you now browse to your site and change to the new theme you should see the Courses branch at the end of your custom menu that contains all of the categories, sub categories and courses for your site.&lt;br /&gt;
&lt;br /&gt;
==Full source==&lt;br /&gt;
===config.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$THEME-&amp;gt;name = &#039;coursecategorymenu&#039;;&lt;br /&gt;
$THEME-&amp;gt;parents = array(&#039;standard&#039;, &#039;base&#039;);&lt;br /&gt;
$THEME-&amp;gt;rendererfactory = &#039;theme_overridden_renderer_factory&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===renderers.php===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class theme_coursecategorymenu_core_renderer extends core_renderer {&lt;br /&gt;
 &lt;br /&gt;
    protected function render_custom_menu(custom_menu $menu) {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
        &lt;br /&gt;
        require_once($CFG-&amp;gt;dirroot.&#039;/course/lib.php&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $branch = $menu-&amp;gt;add(get_string(&#039;courses&#039;, &#039;theme_coursecategorymenu&#039;), null, null, 10000);&lt;br /&gt;
        &lt;br /&gt;
        $categorytree = get_course_category_tree();&lt;br /&gt;
        foreach ($categorytree as $category) {&lt;br /&gt;
            $this-&amp;gt;add_category_to_custommenu($branch, $category);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return parent::render_custom_menu($menu);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    protected function add_category_to_custommenu(custom_menu_item $parent, stdClass $category) {&lt;br /&gt;
        $branch = $parent-&amp;gt;add($category-&amp;gt;name, new moodle_url(&#039;/course/category.php&#039;, array(&#039;id&#039; =&amp;gt;  $category-&amp;gt;id)));&lt;br /&gt;
        if (!empty($category-&amp;gt;categories)) {&lt;br /&gt;
            foreach ($category-&amp;gt;categories as $subcategory) {&lt;br /&gt;
                $this-&amp;gt;add_category_to_custommenu($branch, $subcategory);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        if (!empty($category-&amp;gt;courses)) {&lt;br /&gt;
            foreach ($category-&amp;gt;courses as $course) {&lt;br /&gt;
                $branch-&amp;gt;add($course-&amp;gt;shortname, new moodle_url(&#039;/course/view.php&#039;, array(&#039;id&#039; =&amp;gt; $course-&amp;gt;id)), $course-&amp;gt;fullname);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
===lang/en/theme_===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$string[&#039;courses&#039;] = &#039;Courses&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]]&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/3/node-menunav/ YUI 3 Menunav component the custom menu uses]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=82884</id>
		<title>Användare:Sam Hemelryk</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk&amp;diff=82884"/>
		<updated>2011-04-19T03:28:14Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I am a senior developer at Moodle and have been with the project since the June 2009.&lt;br /&gt;
&lt;br /&gt;
For those interested I have written a tutorial on my Moodle development process with Git: [[User:Sam_Hemelryk/My_Moodle_Git_workflow]]&lt;br /&gt;
&lt;br /&gt;
A short list of helpful documents I have created:&lt;br /&gt;
&lt;br /&gt;
* [[Development:Themes 2.0]]&lt;br /&gt;
* [[Development:Themes 2.0 creating your first theme]] - A quick step by step guide to creating your first theme.&lt;br /&gt;
* [[Development:Themes 2.0 overriding a renderer]] - A tutorial on creating a custom renderer and changing the HTML Moodle produces.&lt;br /&gt;
* [[Development:Themes 2.0 How to use images within your theme]] - Explains how to use and override images within your theme.&lt;br /&gt;
* [[Development:Themes 2.0 adding a settings page]] - Looks at how to add a setting page making your theme easily customisable.&lt;br /&gt;
* [[Development:Themes 2.0 extending the custom menu]] - Customising the custom menu.&lt;br /&gt;
* [[Development:Themes 2.0 how to make the dock horizontal]] - Modifying the dock to make it horizontal.&lt;br /&gt;
* [[Development:Themes 2.0 adding upgrade code]]&lt;br /&gt;
* [[Development:Styling and customising the dock]] - How to style and customise the dock.&lt;br /&gt;
* [[Development:Using jQuery with Moodle 2.0]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=82883</id>
		<title>Användare:Sam Hemelryk/My Moodle Git workflow</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=82883"/>
		<updated>2011-04-19T03:23:23Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* What to do when your work gets rejected */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document is a sort of tutorial/inspection of my personal development workflow when working on Moodle with Git.&lt;br /&gt;
&lt;br /&gt;
==Creating the repositories==&lt;br /&gt;
Ok so the very first step is to create several Moodle git repositories, one for each major branch of Moodle being worked on.&lt;br /&gt;
&lt;br /&gt;
At the time of writing the major branches are MOODLE_19_STABLE, MOODLE_20_STABLE and master.&lt;br /&gt;
&lt;br /&gt;
The reason for this is that that way we have a separate site for each Moodle branch that we can test on easily. Yes you will have three sites but you won&#039;t have to worry about swtiching your site when you change branches.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Create a directory to create the repositories within===&lt;br /&gt;
&lt;br /&gt;
Personally I use Ubuntu (Linux) and I chose to create my repositories within a folder I created in /var/www. If you are using windows I would instead suggest creating C:/www/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www&lt;br /&gt;
mkdir repositories&lt;br /&gt;
cd repositories&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 2: Create a master repository===&lt;br /&gt;
This is the easiest of the branches to create a repository for.&lt;br /&gt;
&lt;br /&gt;
Within your repositories directory create a new directory called master and move into it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir master&lt;br /&gt;
cd master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we want to clone the Moodle source from the offical Moodle git repository as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a new directory called moodle within the master directory we created just before.&lt;br /&gt;
&lt;br /&gt;
That new moodle directory should contain the Moodle source code as a git repository.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve got our main git repository we need to add our github account as a remote so that we can push to it later:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd moodle&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This adds your moodle repository on github as a remote called github that you can push to later.&lt;br /&gt;
&lt;br /&gt;
Finally before we move onto the next repository we need to create a data directory because we know we will need that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3: Create a MOODLE_20_STABLE repository===&lt;br /&gt;
&lt;br /&gt;
The next repository we create will be for the MOODLE_20_STABLE branch.&lt;br /&gt;
To start with get back to the repositories directory that we created earlier and create a directory called MOODLE_20_STABLE within that.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories&lt;br /&gt;
mkdir MOODLE_20_STABLE&lt;br /&gt;
cd MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create a new clone of the main Moodle repository like we did for the master branch above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once we have done that move into the moodle directory.&lt;br /&gt;
&lt;br /&gt;
By default the master branch is the branch that is created, however we don&#039;t want that for this repository. Instead we want the MOODLE_20_STABLE branch.&lt;br /&gt;
&lt;br /&gt;
To do this we checkout local branch based upon the official MOODLE_20_STABLE branch as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b MOODLE_20_STABLE origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once we have created that branch we can delete the local master branch so that we don&#039;t accidentally ever work on it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git branch -D master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then like we did for master we add our github repository as a remote:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally create a data directory we can use when we have install the site:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 4: Create a MOODLE_19_STABLE repository===&lt;br /&gt;
&lt;br /&gt;
This step is identical to the above step except we are using the MOODLE_19_STABLE branch instead of the MOODLE_20_STABLE branch.&lt;br /&gt;
The commands for this are as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories&lt;br /&gt;
mkdir MOODLE_19_STABLE&lt;br /&gt;
cd MOODLE_19_STABLE&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
git checkout -b MOODLE_19_STABLE origin/MOODLE_19_STABLE&lt;br /&gt;
git branch -D master&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 5: Install the sites===&lt;br /&gt;
Now I can&#039;t tell you how to do this on your own machine however what I would recommend is that you create a link from your web root to the moodle directory of each branch.&lt;br /&gt;
&lt;br /&gt;
If you are using linux and your webroot is /var/www/localhost you would do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/localhost/&lt;br /&gt;
ln -s /var/www/repositories/master/moodle master&lt;br /&gt;
ln -s /var/www/repositories/MOODLE_20_STABLE/moodle MOODLE_20_STABLE&lt;br /&gt;
ln -s /var/www/repositories/MOODLE_19_STABLE/moodle MOODLE_19_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With that done you should be able to browse to each repository with the following URL&#039;s&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://localhost/master/&lt;br /&gt;
http://localhost/MOODLE_20_STABLE/&lt;br /&gt;
http://localhost/MOODLE_19_STABLE/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once that is done you need to browse to each site and complete the installation.&lt;br /&gt;
&lt;br /&gt;
Under this method your will need to ensure you set the configuration option sessioncookiepath to the URI of your site. You can either do this in the admin interfaces or add the following to your config.php file for each site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// For the master site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/master/&#039;;&lt;br /&gt;
// For the MOODLE_20_STABLE site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/MOODLE_20_STABLE/&#039;;&lt;br /&gt;
// For the MOODLE_19_STABLE site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/MOODLE_19_STABLE/&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Failure to do this will mean that when you log in at one site and then visit the next you will have to log in again and your session on the first site will no longer work.&lt;br /&gt;
&lt;br /&gt;
Now that you have got 3 repositories, one for each main branch, and set up a site for each you are ready to start development.&lt;br /&gt;
&lt;br /&gt;
==Before you start work each day==&lt;br /&gt;
Before you start work each day you should update each of the repositories you have created to ensure that you are always working with up to date versions of Moodle.&lt;br /&gt;
&lt;br /&gt;
You should also take this opportunity to update the repositories on your github account to ensure they are always up to date.&lt;br /&gt;
&lt;br /&gt;
To start with lets update the master repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This moves to the master repository and then tells git for fetch all of the changes from your remote repositories and clean up any old branches it is aware of.&lt;br /&gt;
&lt;br /&gt;
Once that operation has completed you should update your master branch&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout master&lt;br /&gt;
git pull&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before you do that it pays to make sure you don&#039;t have any uncommit changes, if you do DON&#039;T TRY IT. There would be a good chance you will encounter problems. Instead finish what you are working on, commit your changes and then update your master branch.&lt;br /&gt;
&lt;br /&gt;
Next we will update the github repositories by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github refs/remotes/origin/master:master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells git to push the master branch from origin (the offical Moodle repository) to the master branch on our github account.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve updated the master repository and your github account its time to update the MOODLE_20_STABLE and MOODLE_19_STABLE branches.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_20_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github refs/remotes/origin/MOODLE_20_STABLE:MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_19_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_19_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github refs/remotes/origin/MOODLE_19_STABLE:MOODLE_19_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working on a Moodle issue==&lt;br /&gt;
&lt;br /&gt;
This part of the document looks at how I go about working on an MDL issue from the Moodle tracker.&lt;br /&gt;
&lt;br /&gt;
At Moodle HQ we use the scrum methodology we sees us choose several issues to include in a scrum which we then work on for the period of the scrum. As a community member its more likely you will just be choosing issues that you are passionate about.&lt;br /&gt;
&lt;br /&gt;
Either way once you have found an issue to work on you are ready to start.&lt;br /&gt;
&lt;br /&gt;
For the purpose of this part of the document lets say I am going to work on bug MDL-12345.&lt;br /&gt;
&lt;br /&gt;
==Fixing a bug on the master repository - MDL-12345==&lt;br /&gt;
&lt;br /&gt;
The first step is to create a local branch to make changes on, to do this we will start our work on the master repository.&lt;br /&gt;
&lt;br /&gt;
When fixing an issue I find it easiest to fix the issue on the master branch first and then move my changes to the other branches.&lt;br /&gt;
&lt;br /&gt;
The VERY first thing you should do when you start working on a Moodle issue is make sure you have assigned it to yourself and then click the start progress button.&lt;br /&gt;
&lt;br /&gt;
This way other users know that you are activly working on the bug and no one from HQ will steal it from you.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Creating a local branch===&lt;br /&gt;
&lt;br /&gt;
So first get to the master repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once there we create a new branch as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b wip-MDL-12345-master origin/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command checks out a new branch called wip-MDL-12345-master that is based upon origin/master.&lt;br /&gt;
&lt;br /&gt;
origin/master is of course the master branch on the official Moodle repository (git.moodle.org/moodle.git).&lt;br /&gt;
&lt;br /&gt;
The name of the branch is also very important. It is essentially telling us three things.&lt;br /&gt;
&lt;br /&gt;
; wip : This stands for work in progress, it helps people see that you are currently working on this branch and that they shouldn&#039;t base there work on it because it will likely change.&lt;br /&gt;
; MDL-12345 : This is of course the Moodle bug number. It helps people quickly identify what you are working on.&lt;br /&gt;
; master : This is the branch we are making changes on. It helps people quickly understand where the changes are being made.&lt;br /&gt;
&lt;br /&gt;
You can optionally add more to the end of the branch name such as a key word that identifies the area or a date at which you started work e.g.&lt;br /&gt;
&lt;br /&gt;
* wip-MDL-12345-master-navigation-changes&lt;br /&gt;
* wip-MDL-12345-master-20110418&lt;br /&gt;
&lt;br /&gt;
That is up to you, personally I&#039;m not a fan of it, however the rest is all required to help integrate your work.&lt;br /&gt;
&lt;br /&gt;
Either way now you have a branch, mine is called wip-MDL-12345-master.&lt;br /&gt;
&lt;br /&gt;
===Step 2: Make changes===&lt;br /&gt;
&lt;br /&gt;
Now that you have created you branch you are ready to make changes.&lt;br /&gt;
&lt;br /&gt;
I&#039;ll let you make whatever changes you are need, once you have made changes move onto the next step.&lt;br /&gt;
&lt;br /&gt;
Before you do move on however make sure that your code meets the high quality of code Moodle requires.&lt;br /&gt;
&lt;br /&gt;
You can find information about that on the moodle docs here: https://docs.moodle.org/en/Development:Coding_style&lt;br /&gt;
&lt;br /&gt;
The following are common mistakes:&lt;br /&gt;
&lt;br /&gt;
* Incorrect white space&lt;br /&gt;
** Tabs instead of spaces&lt;br /&gt;
** Extra spaces at the end of lines&lt;br /&gt;
** Multiple new lines&lt;br /&gt;
** Forgetting to put spaces between function arguments&lt;br /&gt;
* Incorrect commit messages (read on to find out about writing a good commit message)&lt;br /&gt;
* Incorrect variable or function names&lt;br /&gt;
&lt;br /&gt;
Making these sort of mistakes can lead to your code being rejected despite it working correctly.&lt;br /&gt;
&lt;br /&gt;
I would &#039;&#039;&#039;strongly&#039;&#039;&#039; suggest while learning Moodle development that you use [[User:Tim Hunt|Tim Hunt&#039;s]] fantastic [https://github.com/timhunt/moodle-local_codechecker Code Checker] plugin.&amp;lt;br /&amp;gt;&lt;br /&gt;
You&#039;ll find information on how to use it within its README file and it will pick up many of the things that may lead to your work being rejected.&lt;br /&gt;
&lt;br /&gt;
Or course it will be reviewed in regards to security, usability and the other important factors of code development.&lt;br /&gt;
&lt;br /&gt;
===Step 3: Commit your changes===&lt;br /&gt;
&lt;br /&gt;
Now that you have made your changes you are getting ready to commit them.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is check your changes. To do this run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see all of the files you have changes highlighted in red.&lt;br /&gt;
&lt;br /&gt;
Next you need to stage all of the files you want to commit.&lt;br /&gt;
&lt;br /&gt;
To do this you add the files to the stage using the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git add lib/modifiedfile.php&lt;br /&gt;
git add lib/newfile.php&lt;br /&gt;
git add theme/base/style/core.css&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why not just commit all changes. Many of the git guides you read will tell you above git commit -a which commits all of the changes you have made.&lt;br /&gt;
&lt;br /&gt;
We&#039;ve hardly being using git here at Moodle and already I&#039;ve seen several people accidentally commit changes that they didn&#039;t mean to.&lt;br /&gt;
&lt;br /&gt;
Staging files like this ENSURES you only commit things you intend to.&lt;br /&gt;
&lt;br /&gt;
Now that you have staged your changes/new files you are ready to commit. The following command commits your changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git commit -m &amp;quot;MDL-12345 enrol - Fixed up a couple of enrolment bugs&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command commits your changes with the commit message &amp;quot;MDL-12345 enrol - Fixed up a couple of enrolment bugs&amp;quot;.&lt;br /&gt;
It&#039;s very important to Moodle that you format your commit messages like this.&lt;br /&gt;
They consist of three parts:&lt;br /&gt;
&lt;br /&gt;
# The MDL bug number in this case MDL-12345&lt;br /&gt;
# The area you made changes to in this case enrol&lt;br /&gt;
# A short description of what you did, in this case I fixed a couple of enrolment bugs.&lt;br /&gt;
&lt;br /&gt;
When you commit your message you will see something like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[master 19a484e] changes&lt;br /&gt;
 1 files changed, 16 insertions(+), 18 deletions(-)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
There is one thing here you need to note down for later, that is the number that appears within the square brackets after the branch name, in my case it is 19a484e. This is the commit id of the commit I just made.&lt;br /&gt;
&lt;br /&gt;
===Step 4: Pushing your changes to your github account===&lt;br /&gt;
&lt;br /&gt;
Now that you have made changes to your local branch you should push it to your github account so that it can be reviewed and hopefully integrated into Moodle.&lt;br /&gt;
&lt;br /&gt;
Doing this is very simple just run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we are telling git to push the branch wip-MDL-12345-master to the remote called github which we added when setting up our git repositories.&lt;br /&gt;
And just like that you&#039;ve made a branch that contains your work and pushed it to github ready to get it reviewed.&lt;br /&gt;
&lt;br /&gt;
==Moving your changes to another branch==&lt;br /&gt;
Now that you have made changes to the master branch you need to decide whether it is appropriate make those changes on any of the other branches.&lt;br /&gt;
Most likely if you are fixing a bug you will need to make the changes on the MOODLE_20_STABLE branch as well, and perhaps the MOODLE_19_STABLE branch if it is a security bug.&lt;br /&gt;
&lt;br /&gt;
Lets assume for MDL-12345 that I fixed earlier that it should be ported to MOODLE_20_STABLE as well.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Creating a local MOODLE_20_STABLE branch===&lt;br /&gt;
&lt;br /&gt;
To start with I need to move to the MOODLE_20_STABLE repository as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once there I need to create a new branch based upon the MOODLE_20_STABLE branch that is going to contain my changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b wip-MDL-12345-MOODLE_20_STABLE origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is very similar to the branch we created for the changes to the master branch except that I have subsituted MOODLE_20_STABLE in place of master. This is because the new branch we are creating is based upon the MOODLE_20_STABLE branch on the offical Moodle git repository and contains changes for that branch.&lt;br /&gt;
&lt;br /&gt;
===Step 2: Cherry-picking my changes===&lt;br /&gt;
Once we have a branch for our changes I am ready to make them again. There is however with git an easy way to do this, cherry-picking.&lt;br /&gt;
&lt;br /&gt;
Cherry-picking is the process of copying a single commit from one branch to another. In this case I want to cherry pick the commit I made earlier onto the branch I&#039;ve just created.&lt;br /&gt;
&lt;br /&gt;
However before I can do this I need to fetch the changes I made from the github repository. I need to do this because I made that changes of a totally separate local repository remember.&lt;br /&gt;
&lt;br /&gt;
So to update my repository with the latest changes I run the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command tells git to look at each remote and get any new changes (it also removes any branches that have been deleted).&lt;br /&gt;
Once it has completed you will be ready to cherry pick the commit. To do so you use the following command but replace my commit is with yours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git cherry-pick 19a484e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Providing there are no conflicts your branch will now contain a copy of the changes you made to the master branch.&lt;br /&gt;
If there are conficts that you will need to resolve them and commit your changes however you can search for another tutorial about how to do that,&lt;br /&gt;
&lt;br /&gt;
Now I know at this point that there will be some of you who are saying &#039;Whoops I forgot what my commit id was!&#039;. If this is you don&#039;t worry, its pretty easy to find it providing you used a proper commit message like I described above.&lt;br /&gt;
Simply run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git log --oneline origin/master..github/wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command shows you all of the commits that are in the wip-MDL-12345-master at your github account but are not in the master branch at the offical Moodle repository.&lt;br /&gt;
You can then cherry-pick the commits shown there (the commit ID&#039;s should be highlighted in yellow).&lt;br /&gt;
&lt;br /&gt;
Once you have cherry-picked your commits its time to check that everything worked, run the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see something like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# On branch wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
# Your branch is ahead of &#039;origin/MOODLE_20_STABLE&#039; by 1 commit.&lt;br /&gt;
#&lt;br /&gt;
nothing to commit (working directory clean)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is very handy as it tells you that your branch is ahead of the offical MOODLE_20_STABLE branch by one commit.&lt;br /&gt;
You can also check that your commit contains the changes you think by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git diff origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command shows you all of the changes you have made as a diff.&lt;br /&gt;
&lt;br /&gt;
Now that you know that your commit is there you and that it is correct it is time to push it to your github account.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And thats it.&lt;br /&gt;
&lt;br /&gt;
You github account should now have two branches on it:&lt;br /&gt;
&lt;br /&gt;
; wip-MDL-12345-master : This branch is the changes you have made for the master branch&lt;br /&gt;
; wip-MDL-12345-MOODLE_20_STABLE : This branch is those same changes but for the MOODLE_20_STABLE branch&lt;br /&gt;
&lt;br /&gt;
Now you are ready to create PULL requests so that your work gets reviewed and hopefully integrated.&lt;br /&gt;
&lt;br /&gt;
==Creating PULL requests==&lt;br /&gt;
Now that you&#039;ve got a branch with changes for your MDL issue its time to create some PULL requests to get it integrated.&lt;br /&gt;
&lt;br /&gt;
===Creating a PULL request for the master branch===&lt;br /&gt;
&lt;br /&gt;
So you have successfully fixed the bug MDL-12345, you have created two branches one for master and one for MOODLE_20_STABLE. It is time to create a PULL request for each of these branches.&lt;br /&gt;
&lt;br /&gt;
First lets create a PULL request for the master branch:&lt;br /&gt;
&lt;br /&gt;
# Browse to tracker.moodle.org/browse/MDL-12345&lt;br /&gt;
# When the page loads log in if you haven&#039;t already.&lt;br /&gt;
# Click on the button in the top right labelled `Create issue`&lt;br /&gt;
# Change Project to `Pull Requests`&lt;br /&gt;
# Change Issue type to `Pull Request`&lt;br /&gt;
# Click create&lt;br /&gt;
&lt;br /&gt;
This takes you to a screen where you can enter the details for the PULL request.&lt;br /&gt;
&lt;br /&gt;
You should fill it out in the following way:&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
This is the summary for the PULL request, you should copy and paste the summary from the MDL issue here.&lt;br /&gt;
For MDL-12345 the summary is `alphabetization of UI different on left and right sides` so that&#039;s what I will use.&lt;br /&gt;
&lt;br /&gt;
====Affects Versions====&lt;br /&gt;
This is the version that your branch is changing, in the case of this PULL request I will select `master`.&lt;br /&gt;
&lt;br /&gt;
====Security level====&lt;br /&gt;
If the issue you are working on is a security issue you should set this to the same level that the issue is set to. If its not a security issue or you don&#039;t know just leave it as none.&lt;br /&gt;
&lt;br /&gt;
====Pull from repository====&lt;br /&gt;
This is the repository that the branch is at, for you this will be your github accont. If you head to http://github.com/yourname/moodle you will see a box that has three options SSH, HTTP, and Git read only, click Git Read Only and then copy the contents of the text box into the repositry field of the PULL request. &lt;br /&gt;
For me that is git://github.com/yourname/moodle.git&lt;br /&gt;
&lt;br /&gt;
====Pull branch====&lt;br /&gt;
This is the name of the branch that contains your changes. For me that is wip-MDL-12345-master.&lt;br /&gt;
&lt;br /&gt;
====Pull Diff URL====&lt;br /&gt;
This is the URL to a page that shows the changes that you&#039;ve made on your branch. Github is nice in that it has a pretty interface for that. To get to the interface follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Browse to https://github.com/youraccount/moodle&lt;br /&gt;
# Click `Switch Branches` and then click on the branch you changes are based upon, in my case master.&lt;br /&gt;
# Click the button labelled `Branch List`&lt;br /&gt;
# Locate your branch in the list and click the `Compare button` for me this was the compare button to the right of wip-MDL-12345-master.&lt;br /&gt;
# Copy the URL in your browse and paste it into the Pull Diff URL of the PULL request.&lt;br /&gt;
&lt;br /&gt;
For me this URL was: https://github.com/yourname/moodle/compare/master...wip-MDL-23532-master&lt;br /&gt;
For the MOODLE_20_STABLE branch this would be: https://github.com/yourname/moodle/compare/MOODLE_20_STABLE...wip-MDL-23532-MOODLE_20_STABLE&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
The description should contain several bits of important information:&lt;br /&gt;
&lt;br /&gt;
# A short description of what your patch does&lt;br /&gt;
# Notes about that changes you&#039;ve made that might help the integrator understand what you did when he/she is reviewing it.&lt;br /&gt;
# Testing instructions that guide the testers through testing your changes.&lt;br /&gt;
&lt;br /&gt;
====Components====&lt;br /&gt;
Select general from the components list, general is the only option.&lt;br /&gt;
&lt;br /&gt;
====Finishing up====&lt;br /&gt;
Once you have filled in the fields as above click `Create`. This should create you PULL request and then take you to view it.&lt;br /&gt;
&lt;br /&gt;
Its important to remember that there is still one thing you need to do and that is link to the original issue.&lt;br /&gt;
While you are still logged in click the `More Actions` button and select `Link issue`, in the dialoug that pops up change the `This issue` field to `will help resolve`, type MDL-12345 into the issues field, and then type `Linking to MDL-12345` into the comments box. Once you&#039;ve done that simple click Link.&amp;lt;br /&amp;gt;I should add that the comment isn&#039;t really required. It&#039;s just something I personally like doing.&lt;br /&gt;
&lt;br /&gt;
Time to create the PULL request for the other branches.&lt;br /&gt;
&lt;br /&gt;
===Creating the PULL request for MOODLE_20_STABLE===&lt;br /&gt;
Once you&#039;ve created the PULL request for the master branch it is time to create the PULL request for the MOODLE_20_STABLE branch.&lt;br /&gt;
This is as easy as can be, click Create Issue in the top right, select PULL project and choose Pull Request and then click create.&lt;br /&gt;
On the next screen enter the following details:&lt;br /&gt;
&lt;br /&gt;
; Summary : Copy the summary from the previous PULL Request&lt;br /&gt;
; Affects Versions : Select MOODLE_20_STABLE&lt;br /&gt;
; Security level : Same as the MDL&lt;br /&gt;
; Pull from repository : Copy from the previous PULL request&lt;br /&gt;
; Pull Branch : wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
; Pull Diff URL : https://github.com/yourname/moodle/compare/MOODLE_20_STABLE...wip-MDL-23532-MOODLE_20_STABLE&lt;br /&gt;
; Description : Copy from the previous PULL request&lt;br /&gt;
; Component : general&lt;br /&gt;
&lt;br /&gt;
Then click create to create the PULL request.&lt;br /&gt;
&lt;br /&gt;
Once the PULL request has been create don&#039;t forget to link to the MDL issue like we did for the previous PULL request.&lt;br /&gt;
&lt;br /&gt;
==Resolving the issue==&lt;br /&gt;
The final step for the MDL issue now that you have created the two PULL requests is to Resolve the issue (do not close it, just resolve).&lt;br /&gt;
&lt;br /&gt;
You can do this by logging into tracker, browsing to the MDL issue, and clicking the resolve button.&lt;br /&gt;
&lt;br /&gt;
If your fixes are integrated the tester will close the issue, otherwise if it doesn&#039;t get integrated someone will reopen the MDL.&lt;br /&gt;
&lt;br /&gt;
==Rebasing after the weekly release==&lt;br /&gt;
As many of you will be aware on Wednesday after the latest weekly has been released a comment will be added to all PULL requests that are still open.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The main moodle.git repository has just been updated with latest weekly modifications.&lt;br /&gt;
You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator&#039;s life easier next week.&lt;br /&gt;
&lt;br /&gt;
TIA and ciao :)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a message that is bulk added as is done so as a polite request. While it&#039;s not essential for you to rebase your work it really does help the integrators as its much easier to see what is going on and greatly reduces the chance of conflicts (because you&#039;ll solve them when you rebase).&lt;br /&gt;
&lt;br /&gt;
The good news is that rebasing your work is EASY!&lt;br /&gt;
&lt;br /&gt;
For the following example lets assume I created the two PULL requests above on Wednesday morning and the weekly was released on Wednesday afternoon. This means that my branch doesn&#039;t have the changes that have just been released and I need to rebase them.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Rebasing the wip-MDL-12345-master===&lt;br /&gt;
&lt;br /&gt;
The first step is to rebase my work that is based upon the master branch. So first move to the master repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next thing we have to do is get all of the changes from the remote repositories, this will fetch down all of the latest changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now before the next step make sure that you don&#039;t have any uncommit changes, if you do finish that work, commit it, then proceed to the next step which is updating your local master.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout master&lt;br /&gt;
git pull&lt;br /&gt;
git push master github&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that your local master is up to date, and has you&#039;ve updated you master branch at github you are ready to rebase!&lt;br /&gt;
At this point we want to checkout the branch we are going to rebase, in this case wip-MDL-12345-master and then we are going to rebase origin/master which is the official Moodle master branch (and the branch our branch is based upon).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout wip-MDL-12345-master&lt;br /&gt;
git rebase origin/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once that command has completed your branch wip-MDL-12345-master will be completely up to date. Before you are done however you need to push the rebased wip-MDL-12345-master up to your github account so that its the branch the integrator sees.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push -f github wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that command is just about identical to the command we used when we first pushed our branch to our github account, there is however one VERY important difference, the &#039;&#039;&#039;-f&#039;&#039;&#039; option.&lt;br /&gt;
The &#039;&#039;&#039;-f&#039;&#039;&#039; option tells git to force the push, this is required because when you rebase all of your commit id&#039;s will change and unless you tell git to force it will see that they have changed and not allow you to push your work.&lt;br /&gt;
&lt;br /&gt;
Thats it! you&#039;ve now rebased your work and the integrators will be happy again :)&lt;br /&gt;
&lt;br /&gt;
===Step 2: Rebasing wip-MDL-12345-MOODLE_20_STABLE===&lt;br /&gt;
Now that we&#039;ve rebased our work that was based upon the master branch it is time to rebase the MOODLE_20_STABLE version.&lt;br /&gt;
This step is just about identical to the previous step except we substitute &#039;&#039;master&#039;&#039; for &#039;&#039;MOODLE_20_STABLE&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_20_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github MOODLE_20_STABLE&lt;br /&gt;
git checkout wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
git rebase origin/MOODLE_20_STABLE&lt;br /&gt;
git push -f github wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done!&lt;br /&gt;
&lt;br /&gt;
==So your work got rejected... what now?==&lt;br /&gt;
First up don&#039;t give up, we (Moodle integrators) don&#039;t just reject code willy-nilly, we always provide a reason.&lt;br /&gt;
&lt;br /&gt;
There are a couple of different paths that this may lead you down:&lt;br /&gt;
# More work needed: This happens if you have fixed half of the bug, or some of the bugs, but not all/completely. In this case you just need to finish off the MDL and then create new PULL requests.&lt;br /&gt;
# Bugs + white space issues: If this is the case you need to fix up what ever was spotted and then create new PULL requests.&lt;br /&gt;
# Not appropriate for a stable branch: This happens if the integrator decides that your work shouldn&#039;t get into the STABLE branch but is still OK for the master branch. Things like new features or improvements are likely to head down this path. If this is the case then everything is done, your work will have been integrated into master and you will just have to wait until the next major release (2.1, 2.2 etc).&lt;br /&gt;
# Not appropriate for core: If this happens it means that the integrator has decided that the work you&#039;ve done isn&#039;t suitable to go into the main Moodle code base. If this is the case and you still want to use your branches that is fine, just leave them up on your github account and whenever you need to use them just merge your branch into your sites repository.&lt;br /&gt;
&lt;br /&gt;
==The extra mile==&lt;br /&gt;
Now as many of you may have guessed by the time you are working on several different issues and managing several repositories the process I&#039;ve described here seems VERY repetitive. And it &#039;&#039;&#039;IS!&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you talk to any HQ developer they will tell you they deal with it in their own way, anything from scripts, to custom config files, through to virtual machine snapshots.&lt;br /&gt;
&lt;br /&gt;
Personally I have a couple of bash scripts that I wrote to help me manage my workflow.&lt;br /&gt;
&lt;br /&gt;
The first script I use I run after each weekly release and it does the following things:&lt;br /&gt;
&lt;br /&gt;
* Moves to each repository and does the following&lt;br /&gt;
*# Fetches all remote changes&lt;br /&gt;
*# Checks whether it is safe to update my local main release branches and does that if it is safe&lt;br /&gt;
*# Updates all main release branches on my github account&lt;br /&gt;
&lt;br /&gt;
The second script I run on every site that I have installed, it does the following&lt;br /&gt;
&lt;br /&gt;
* Goes to each site I have installed and does the following&lt;br /&gt;
*# Overwrites the database with a stable snapshot&lt;br /&gt;
*# Overwrites the moodle data directory with a stable snapshot taken at the same time as the database one.&lt;br /&gt;
*# Upgrades the moodle site if required&lt;br /&gt;
*# Takes a snapshot of the database and Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The third script I run whenever I start working on a new issue and it restores the stable snapshot of a sites database and moodle data directory.&lt;br /&gt;
&lt;br /&gt;
These three scripts allow me to very easily ensure I am working with the latest changes and that I can easily restore to a point I know is stable and safe.&lt;br /&gt;
&lt;br /&gt;
There was a fourth script I used to use but don&#039;t any more that also rebased any unmerged branches however I found it to be far to problematic and I prefer to do it myself so that I know exactly what is going on.&lt;br /&gt;
&lt;br /&gt;
==Useful links==&lt;br /&gt;
The following are links I found useful while learning Git.&lt;br /&gt;
&lt;br /&gt;
* [http://help.github.com Github help (http://help.github.com)] Provides EXCELLENT help tutorials that very clearly explain the basic through to the advanced.&lt;br /&gt;
* [http://cheat.errtheblog.com/s/git/ $ cheat git] This is my favourite cheat sheet, straight forward to the point, if you know the concept you&#039;ll find the answer here.&lt;br /&gt;
* [http://gitster.livejournal.com/28309.html Gitsters journal - Fun with FETCH_HEAD] David Mudrak pointed me at this entry which I found INCREDIBLY useful when reviewing other peoples work.&lt;br /&gt;
* [[Development:Git tips]] Moodle docs page with a few handy tips about using Git for Moodle development.&lt;br /&gt;
&lt;br /&gt;
I you&#039;re looking to read/buy a book on Git I&#039;d strongly recommend [http://progit.org/ Pro Git]. I certainly found that the most useful book I read.&lt;br /&gt;
&lt;br /&gt;
[[Category:Git]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=82882</id>
		<title>Användare:Sam Hemelryk/My Moodle Git workflow</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Anv%C3%A4ndare:Sam_Hemelryk/My_Moodle_Git_workflow&amp;diff=82882"/>
		<updated>2011-04-19T03:16:40Z</updated>

		<summary type="html">&lt;p&gt;Samhemelryk: /* Step 2: Rebasing wip-MDL-12345-MOODLE_20_STABLE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document is a sort of tutorial/inspection of my personal development workflow when working on Moodle with Git.&lt;br /&gt;
&lt;br /&gt;
==Creating the repositories==&lt;br /&gt;
Ok so the very first step is to create several Moodle git repositories, one for each major branch of Moodle being worked on.&lt;br /&gt;
&lt;br /&gt;
At the time of writing the major branches are MOODLE_19_STABLE, MOODLE_20_STABLE and master.&lt;br /&gt;
&lt;br /&gt;
The reason for this is that that way we have a separate site for each Moodle branch that we can test on easily. Yes you will have three sites but you won&#039;t have to worry about swtiching your site when you change branches.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Create a directory to create the repositories within===&lt;br /&gt;
&lt;br /&gt;
Personally I use Ubuntu (Linux) and I chose to create my repositories within a folder I created in /var/www. If you are using windows I would instead suggest creating C:/www/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www&lt;br /&gt;
mkdir repositories&lt;br /&gt;
cd repositories&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 2: Create a master repository===&lt;br /&gt;
This is the easiest of the branches to create a repository for.&lt;br /&gt;
&lt;br /&gt;
Within your repositories directory create a new directory called master and move into it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir master&lt;br /&gt;
cd master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we want to clone the Moodle source from the offical Moodle git repository as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a new directory called moodle within the master directory we created just before.&lt;br /&gt;
&lt;br /&gt;
That new moodle directory should contain the Moodle source code as a git repository.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve got our main git repository we need to add our github account as a remote so that we can push to it later:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd moodle&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This adds your moodle repository on github as a remote called github that you can push to later.&lt;br /&gt;
&lt;br /&gt;
Finally before we move onto the next repository we need to create a data directory because we know we will need that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3: Create a MOODLE_20_STABLE repository===&lt;br /&gt;
&lt;br /&gt;
The next repository we create will be for the MOODLE_20_STABLE branch.&lt;br /&gt;
To start with get back to the repositories directory that we created earlier and create a directory called MOODLE_20_STABLE within that.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories&lt;br /&gt;
mkdir MOODLE_20_STABLE&lt;br /&gt;
cd MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now create a new clone of the main Moodle repository like we did for the master branch above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once we have done that move into the moodle directory.&lt;br /&gt;
&lt;br /&gt;
By default the master branch is the branch that is created, however we don&#039;t want that for this repository. Instead we want the MOODLE_20_STABLE branch.&lt;br /&gt;
&lt;br /&gt;
To do this we checkout local branch based upon the official MOODLE_20_STABLE branch as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b MOODLE_20_STABLE origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once we have created that branch we can delete the local master branch so that we don&#039;t accidentally ever work on it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git branch -D master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then like we did for master we add our github repository as a remote:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally create a data directory we can use when we have install the site:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 4: Create a MOODLE_19_STABLE repository===&lt;br /&gt;
&lt;br /&gt;
This step is identical to the above step except we are using the MOODLE_19_STABLE branch instead of the MOODLE_20_STABLE branch.&lt;br /&gt;
The commands for this are as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories&lt;br /&gt;
mkdir MOODLE_19_STABLE&lt;br /&gt;
cd MOODLE_19_STABLE&lt;br /&gt;
git clone git://git.moodle.org/moodle.git moodle&lt;br /&gt;
git checkout -b MOODLE_19_STABLE origin/MOODLE_19_STABLE&lt;br /&gt;
git branch -D master&lt;br /&gt;
git remote add github git@github.com:yourname/moodle.git&lt;br /&gt;
cd ..&lt;br /&gt;
mkdir data&lt;br /&gt;
sudo chmod -R 777 data&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 5: Install the sites===&lt;br /&gt;
Now I can&#039;t tell you how to do this on your own machine however what I would recommend is that you create a link from your web root to the moodle directory of each branch.&lt;br /&gt;
&lt;br /&gt;
If you are using linux and your webroot is /var/www/localhost you would do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/localhost/&lt;br /&gt;
ln -s /var/www/repositories/master/moodle master&lt;br /&gt;
ln -s /var/www/repositories/MOODLE_20_STABLE/moodle MOODLE_20_STABLE&lt;br /&gt;
ln -s /var/www/repositories/MOODLE_19_STABLE/moodle MOODLE_19_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With that done you should be able to browse to each repository with the following URL&#039;s&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://localhost/master/&lt;br /&gt;
http://localhost/MOODLE_20_STABLE/&lt;br /&gt;
http://localhost/MOODLE_19_STABLE/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once that is done you need to browse to each site and complete the installation.&lt;br /&gt;
&lt;br /&gt;
Under this method your will need to ensure you set the configuration option sessioncookiepath to the URI of your site. You can either do this in the admin interfaces or add the following to your config.php file for each site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// For the master site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/master/&#039;;&lt;br /&gt;
// For the MOODLE_20_STABLE site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/MOODLE_20_STABLE/&#039;;&lt;br /&gt;
// For the MOODLE_19_STABLE site&lt;br /&gt;
$CFG-&amp;gt;sessioncookiepath = &#039;/MOODLE_19_STABLE/&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Failure to do this will mean that when you log in at one site and then visit the next you will have to log in again and your session on the first site will no longer work.&lt;br /&gt;
&lt;br /&gt;
Now that you have got 3 repositories, one for each main branch, and set up a site for each you are ready to start development.&lt;br /&gt;
&lt;br /&gt;
==Before you start work each day==&lt;br /&gt;
Before you start work each day you should update each of the repositories you have created to ensure that you are always working with up to date versions of Moodle.&lt;br /&gt;
&lt;br /&gt;
You should also take this opportunity to update the repositories on your github account to ensure they are always up to date.&lt;br /&gt;
&lt;br /&gt;
To start with lets update the master repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This moves to the master repository and then tells git for fetch all of the changes from your remote repositories and clean up any old branches it is aware of.&lt;br /&gt;
&lt;br /&gt;
Once that operation has completed you should update your master branch&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout master&lt;br /&gt;
git pull&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before you do that it pays to make sure you don&#039;t have any uncommit changes, if you do DON&#039;T TRY IT. There would be a good chance you will encounter problems. Instead finish what you are working on, commit your changes and then update your master branch.&lt;br /&gt;
&lt;br /&gt;
Next we will update the github repositories by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github refs/remotes/origin/master:master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells git to push the master branch from origin (the offical Moodle repository) to the master branch on our github account.&lt;br /&gt;
&lt;br /&gt;
Now that you&#039;ve updated the master repository and your github account its time to update the MOODLE_20_STABLE and MOODLE_19_STABLE branches.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_20_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github refs/remotes/origin/MOODLE_20_STABLE:MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_19_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_19_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github refs/remotes/origin/MOODLE_19_STABLE:MOODLE_19_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Working on a Moodle issue==&lt;br /&gt;
&lt;br /&gt;
This part of the document looks at how I go about working on an MDL issue from the Moodle tracker.&lt;br /&gt;
&lt;br /&gt;
At Moodle HQ we use the scrum methodology we sees us choose several issues to include in a scrum which we then work on for the period of the scrum. As a community member its more likely you will just be choosing issues that you are passionate about.&lt;br /&gt;
&lt;br /&gt;
Either way once you have found an issue to work on you are ready to start.&lt;br /&gt;
&lt;br /&gt;
For the purpose of this part of the document lets say I am going to work on bug MDL-12345.&lt;br /&gt;
&lt;br /&gt;
==Fixing a bug on the master repository - MDL-12345==&lt;br /&gt;
&lt;br /&gt;
The first step is to create a local branch to make changes on, to do this we will start our work on the master repository.&lt;br /&gt;
&lt;br /&gt;
When fixing an issue I find it easiest to fix the issue on the master branch first and then move my changes to the other branches.&lt;br /&gt;
&lt;br /&gt;
The VERY first thing you should do when you start working on a Moodle issue is make sure you have assigned it to yourself and then click the start progress button.&lt;br /&gt;
&lt;br /&gt;
This way other users know that you are activly working on the bug and no one from HQ will steal it from you.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Creating a local branch===&lt;br /&gt;
&lt;br /&gt;
So first get to the master repository:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once there we create a new branch as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b wip-MDL-12345-master origin/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command checks out a new branch called wip-MDL-12345-master that is based upon origin/master.&lt;br /&gt;
&lt;br /&gt;
origin/master is of course the master branch on the official Moodle repository (git.moodle.org/moodle.git).&lt;br /&gt;
&lt;br /&gt;
The name of the branch is also very important. It is essentially telling us three things.&lt;br /&gt;
&lt;br /&gt;
; wip : This stands for work in progress, it helps people see that you are currently working on this branch and that they shouldn&#039;t base there work on it because it will likely change.&lt;br /&gt;
; MDL-12345 : This is of course the Moodle bug number. It helps people quickly identify what you are working on.&lt;br /&gt;
; master : This is the branch we are making changes on. It helps people quickly understand where the changes are being made.&lt;br /&gt;
&lt;br /&gt;
You can optionally add more to the end of the branch name such as a key word that identifies the area or a date at which you started work e.g.&lt;br /&gt;
&lt;br /&gt;
* wip-MDL-12345-master-navigation-changes&lt;br /&gt;
* wip-MDL-12345-master-20110418&lt;br /&gt;
&lt;br /&gt;
That is up to you, personally I&#039;m not a fan of it, however the rest is all required to help integrate your work.&lt;br /&gt;
&lt;br /&gt;
Either way now you have a branch, mine is called wip-MDL-12345-master.&lt;br /&gt;
&lt;br /&gt;
===Step 2: Make changes===&lt;br /&gt;
&lt;br /&gt;
Now that you have created you branch you are ready to make changes.&lt;br /&gt;
&lt;br /&gt;
I&#039;ll let you make whatever changes you are need, once you have made changes move onto the next step.&lt;br /&gt;
&lt;br /&gt;
Before you do move on however make sure that your code meets the high quality of code Moodle requires.&lt;br /&gt;
&lt;br /&gt;
You can find information about that on the moodle docs here: https://docs.moodle.org/en/Development:Coding_style&lt;br /&gt;
&lt;br /&gt;
The following are common mistakes:&lt;br /&gt;
&lt;br /&gt;
* Incorrect white space&lt;br /&gt;
** Tabs instead of spaces&lt;br /&gt;
** Extra spaces at the end of lines&lt;br /&gt;
** Multiple new lines&lt;br /&gt;
** Forgetting to put spaces between function arguments&lt;br /&gt;
* Incorrect commit messages (read on to find out about writing a good commit message)&lt;br /&gt;
* Incorrect variable or function names&lt;br /&gt;
&lt;br /&gt;
Making these sort of mistakes can lead to your code being rejected despite it working correctly.&lt;br /&gt;
&lt;br /&gt;
I would &#039;&#039;&#039;strongly&#039;&#039;&#039; suggest while learning Moodle development that you use [[User:Tim Hunt|Tim Hunt&#039;s]] fantastic [https://github.com/timhunt/moodle-local_codechecker Code Checker] plugin.&amp;lt;br /&amp;gt;&lt;br /&gt;
You&#039;ll find information on how to use it within its README file and it will pick up many of the things that may lead to your work being rejected.&lt;br /&gt;
&lt;br /&gt;
Or course it will be reviewed in regards to security, usability and the other important factors of code development.&lt;br /&gt;
&lt;br /&gt;
===Step 3: Commit your changes===&lt;br /&gt;
&lt;br /&gt;
Now that you have made your changes you are getting ready to commit them.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is check your changes. To do this run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see all of the files you have changes highlighted in red.&lt;br /&gt;
&lt;br /&gt;
Next you need to stage all of the files you want to commit.&lt;br /&gt;
&lt;br /&gt;
To do this you add the files to the stage using the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git add lib/modifiedfile.php&lt;br /&gt;
git add lib/newfile.php&lt;br /&gt;
git add theme/base/style/core.css&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why not just commit all changes. Many of the git guides you read will tell you above git commit -a which commits all of the changes you have made.&lt;br /&gt;
&lt;br /&gt;
We&#039;ve hardly being using git here at Moodle and already I&#039;ve seen several people accidentally commit changes that they didn&#039;t mean to.&lt;br /&gt;
&lt;br /&gt;
Staging files like this ENSURES you only commit things you intend to.&lt;br /&gt;
&lt;br /&gt;
Now that you have staged your changes/new files you are ready to commit. The following command commits your changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git commit -m &amp;quot;MDL-12345 enrol - Fixed up a couple of enrolment bugs&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command commits your changes with the commit message &amp;quot;MDL-12345 enrol - Fixed up a couple of enrolment bugs&amp;quot;.&lt;br /&gt;
It&#039;s very important to Moodle that you format your commit messages like this.&lt;br /&gt;
They consist of three parts:&lt;br /&gt;
&lt;br /&gt;
# The MDL bug number in this case MDL-12345&lt;br /&gt;
# The area you made changes to in this case enrol&lt;br /&gt;
# A short description of what you did, in this case I fixed a couple of enrolment bugs.&lt;br /&gt;
&lt;br /&gt;
When you commit your message you will see something like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[master 19a484e] changes&lt;br /&gt;
 1 files changed, 16 insertions(+), 18 deletions(-)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
There is one thing here you need to note down for later, that is the number that appears within the square brackets after the branch name, in my case it is 19a484e. This is the commit id of the commit I just made.&lt;br /&gt;
&lt;br /&gt;
===Step 4: Pushing your changes to your github account===&lt;br /&gt;
&lt;br /&gt;
Now that you have made changes to your local branch you should push it to your github account so that it can be reviewed and hopefully integrated into Moodle.&lt;br /&gt;
&lt;br /&gt;
Doing this is very simple just run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we are telling git to push the branch wip-MDL-12345-master to the remote called github which we added when setting up our git repositories.&lt;br /&gt;
And just like that you&#039;ve made a branch that contains your work and pushed it to github ready to get it reviewed.&lt;br /&gt;
&lt;br /&gt;
==Moving your changes to another branch==&lt;br /&gt;
Now that you have made changes to the master branch you need to decide whether it is appropriate make those changes on any of the other branches.&lt;br /&gt;
Most likely if you are fixing a bug you will need to make the changes on the MOODLE_20_STABLE branch as well, and perhaps the MOODLE_19_STABLE branch if it is a security bug.&lt;br /&gt;
&lt;br /&gt;
Lets assume for MDL-12345 that I fixed earlier that it should be ported to MOODLE_20_STABLE as well.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Creating a local MOODLE_20_STABLE branch===&lt;br /&gt;
&lt;br /&gt;
To start with I need to move to the MOODLE_20_STABLE repository as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once there I need to create a new branch based upon the MOODLE_20_STABLE branch that is going to contain my changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout -b wip-MDL-12345-MOODLE_20_STABLE origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is very similar to the branch we created for the changes to the master branch except that I have subsituted MOODLE_20_STABLE in place of master. This is because the new branch we are creating is based upon the MOODLE_20_STABLE branch on the offical Moodle git repository and contains changes for that branch.&lt;br /&gt;
&lt;br /&gt;
===Step 2: Cherry-picking my changes===&lt;br /&gt;
Once we have a branch for our changes I am ready to make them again. There is however with git an easy way to do this, cherry-picking.&lt;br /&gt;
&lt;br /&gt;
Cherry-picking is the process of copying a single commit from one branch to another. In this case I want to cherry pick the commit I made earlier onto the branch I&#039;ve just created.&lt;br /&gt;
&lt;br /&gt;
However before I can do this I need to fetch the changes I made from the github repository. I need to do this because I made that changes of a totally separate local repository remember.&lt;br /&gt;
&lt;br /&gt;
So to update my repository with the latest changes I run the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command tells git to look at each remote and get any new changes (it also removes any branches that have been deleted).&lt;br /&gt;
Once it has completed you will be ready to cherry pick the commit. To do so you use the following command but replace my commit is with yours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git cherry-pick 19a484e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Providing there are no conflicts your branch will now contain a copy of the changes you made to the master branch.&lt;br /&gt;
If there are conficts that you will need to resolve them and commit your changes however you can search for another tutorial about how to do that,&lt;br /&gt;
&lt;br /&gt;
Now I know at this point that there will be some of you who are saying &#039;Whoops I forgot what my commit id was!&#039;. If this is you don&#039;t worry, its pretty easy to find it providing you used a proper commit message like I described above.&lt;br /&gt;
Simply run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git log --oneline origin/master..github/wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command shows you all of the commits that are in the wip-MDL-12345-master at your github account but are not in the master branch at the offical Moodle repository.&lt;br /&gt;
You can then cherry-pick the commits shown there (the commit ID&#039;s should be highlighted in yellow).&lt;br /&gt;
&lt;br /&gt;
Once you have cherry-picked your commits its time to check that everything worked, run the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see something like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# On branch wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
# Your branch is ahead of &#039;origin/MOODLE_20_STABLE&#039; by 1 commit.&lt;br /&gt;
#&lt;br /&gt;
nothing to commit (working directory clean)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is very handy as it tells you that your branch is ahead of the offical MOODLE_20_STABLE branch by one commit.&lt;br /&gt;
You can also check that your commit contains the changes you think by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git diff origin/MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This command shows you all of the changes you have made as a diff.&lt;br /&gt;
&lt;br /&gt;
Now that you know that your commit is there you and that it is correct it is time to push it to your github account.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push github wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And thats it.&lt;br /&gt;
&lt;br /&gt;
You github account should now have two branches on it:&lt;br /&gt;
&lt;br /&gt;
; wip-MDL-12345-master : This branch is the changes you have made for the master branch&lt;br /&gt;
; wip-MDL-12345-MOODLE_20_STABLE : This branch is those same changes but for the MOODLE_20_STABLE branch&lt;br /&gt;
&lt;br /&gt;
Now you are ready to create PULL requests so that your work gets reviewed and hopefully integrated.&lt;br /&gt;
&lt;br /&gt;
==Creating PULL requests==&lt;br /&gt;
Now that you&#039;ve got a branch with changes for your MDL issue its time to create some PULL requests to get it integrated.&lt;br /&gt;
&lt;br /&gt;
===Creating a PULL request for the master branch===&lt;br /&gt;
&lt;br /&gt;
So you have successfully fixed the bug MDL-12345, you have created two branches one for master and one for MOODLE_20_STABLE. It is time to create a PULL request for each of these branches.&lt;br /&gt;
&lt;br /&gt;
First lets create a PULL request for the master branch:&lt;br /&gt;
&lt;br /&gt;
# Browse to tracker.moodle.org/browse/MDL-12345&lt;br /&gt;
# When the page loads log in if you haven&#039;t already.&lt;br /&gt;
# Click on the button in the top right labelled `Create issue`&lt;br /&gt;
# Change Project to `Pull Requests`&lt;br /&gt;
# Change Issue type to `Pull Request`&lt;br /&gt;
# Click create&lt;br /&gt;
&lt;br /&gt;
This takes you to a screen where you can enter the details for the PULL request.&lt;br /&gt;
&lt;br /&gt;
You should fill it out in the following way:&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
This is the summary for the PULL request, you should copy and paste the summary from the MDL issue here.&lt;br /&gt;
For MDL-12345 the summary is `alphabetization of UI different on left and right sides` so that&#039;s what I will use.&lt;br /&gt;
&lt;br /&gt;
====Affects Versions====&lt;br /&gt;
This is the version that your branch is changing, in the case of this PULL request I will select `master`.&lt;br /&gt;
&lt;br /&gt;
====Security level====&lt;br /&gt;
If the issue you are working on is a security issue you should set this to the same level that the issue is set to. If its not a security issue or you don&#039;t know just leave it as none.&lt;br /&gt;
&lt;br /&gt;
====Pull from repository====&lt;br /&gt;
This is the repository that the branch is at, for you this will be your github accont. If you head to http://github.com/yourname/moodle you will see a box that has three options SSH, HTTP, and Git read only, click Git Read Only and then copy the contents of the text box into the repositry field of the PULL request. &lt;br /&gt;
For me that is git://github.com/yourname/moodle.git&lt;br /&gt;
&lt;br /&gt;
====Pull branch====&lt;br /&gt;
This is the name of the branch that contains your changes. For me that is wip-MDL-12345-master.&lt;br /&gt;
&lt;br /&gt;
====Pull Diff URL====&lt;br /&gt;
This is the URL to a page that shows the changes that you&#039;ve made on your branch. Github is nice in that it has a pretty interface for that. To get to the interface follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Browse to https://github.com/youraccount/moodle&lt;br /&gt;
# Click `Switch Branches` and then click on the branch you changes are based upon, in my case master.&lt;br /&gt;
# Click the button labelled `Branch List`&lt;br /&gt;
# Locate your branch in the list and click the `Compare button` for me this was the compare button to the right of wip-MDL-12345-master.&lt;br /&gt;
# Copy the URL in your browse and paste it into the Pull Diff URL of the PULL request.&lt;br /&gt;
&lt;br /&gt;
For me this URL was: https://github.com/yourname/moodle/compare/master...wip-MDL-23532-master&lt;br /&gt;
For the MOODLE_20_STABLE branch this would be: https://github.com/yourname/moodle/compare/MOODLE_20_STABLE...wip-MDL-23532-MOODLE_20_STABLE&lt;br /&gt;
&lt;br /&gt;
====Description====&lt;br /&gt;
The description should contain several bits of important information:&lt;br /&gt;
&lt;br /&gt;
# A short description of what your patch does&lt;br /&gt;
# Notes about that changes you&#039;ve made that might help the integrator understand what you did when he/she is reviewing it.&lt;br /&gt;
# Testing instructions that guide the testers through testing your changes.&lt;br /&gt;
&lt;br /&gt;
====Components====&lt;br /&gt;
Select general from the components list, general is the only option.&lt;br /&gt;
&lt;br /&gt;
====Finishing up====&lt;br /&gt;
Once you have filled in the fields as above click `Create`. This should create you PULL request and then take you to view it.&lt;br /&gt;
&lt;br /&gt;
Its important to remember that there is still one thing you need to do and that is link to the original issue.&lt;br /&gt;
While you are still logged in click the `More Actions` button and select `Link issue`, in the dialoug that pops up change the `This issue` field to `will help resolve`, type MDL-12345 into the issues field, and then type `Linking to MDL-12345` into the comments box. Once you&#039;ve done that simple click Link.&amp;lt;br /&amp;gt;I should add that the comment isn&#039;t really required. It&#039;s just something I personally like doing.&lt;br /&gt;
&lt;br /&gt;
Time to create the PULL request for the other branches.&lt;br /&gt;
&lt;br /&gt;
===Creating the PULL request for MOODLE_20_STABLE===&lt;br /&gt;
Once you&#039;ve created the PULL request for the master branch it is time to create the PULL request for the MOODLE_20_STABLE branch.&lt;br /&gt;
This is as easy as can be, click Create Issue in the top right, select PULL project and choose Pull Request and then click create.&lt;br /&gt;
On the next screen enter the following details:&lt;br /&gt;
&lt;br /&gt;
; Summary : Copy the summary from the previous PULL Request&lt;br /&gt;
; Affects Versions : Select MOODLE_20_STABLE&lt;br /&gt;
; Security level : Same as the MDL&lt;br /&gt;
; Pull from repository : Copy from the previous PULL request&lt;br /&gt;
; Pull Branch : wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
; Pull Diff URL : https://github.com/yourname/moodle/compare/MOODLE_20_STABLE...wip-MDL-23532-MOODLE_20_STABLE&lt;br /&gt;
; Description : Copy from the previous PULL request&lt;br /&gt;
; Component : general&lt;br /&gt;
&lt;br /&gt;
Then click create to create the PULL request.&lt;br /&gt;
&lt;br /&gt;
Once the PULL request has been create don&#039;t forget to link to the MDL issue like we did for the previous PULL request.&lt;br /&gt;
&lt;br /&gt;
==Resolving the issue==&lt;br /&gt;
The final step for the MDL issue now that you have created the two PULL requests is to Resolve the issue (do not close it, just resolve).&lt;br /&gt;
&lt;br /&gt;
You can do this by logging into tracker, browsing to the MDL issue, and clicking the resolve button.&lt;br /&gt;
&lt;br /&gt;
If your fixes are integrated the tester will close the issue, otherwise if it doesn&#039;t get integrated someone will reopen the MDL.&lt;br /&gt;
&lt;br /&gt;
==Rebasing after the weekly release==&lt;br /&gt;
As many of you will be aware on Wednesday after the latest weekly has been released a comment will be added to all PULL requests that are still open.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The main moodle.git repository has just been updated with latest weekly modifications.&lt;br /&gt;
You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator&#039;s life easier next week.&lt;br /&gt;
&lt;br /&gt;
TIA and ciao :)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a message that is bulk added as is done so as a polite request. While it&#039;s not essential for you to rebase your work it really does help the integrators as its much easier to see what is going on and greatly reduces the chance of conflicts (because you&#039;ll solve them when you rebase).&lt;br /&gt;
&lt;br /&gt;
The good news is that rebasing your work is EASY!&lt;br /&gt;
&lt;br /&gt;
For the following example lets assume I created the two PULL requests above on Wednesday morning and the weekly was released on Wednesday afternoon. This means that my branch doesn&#039;t have the changes that have just been released and I need to rebase them.&lt;br /&gt;
&lt;br /&gt;
===Step 1: Rebasing the wip-MDL-12345-master===&lt;br /&gt;
&lt;br /&gt;
The first step is to rebase my work that is based upon the master branch. So first move to the master repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/master/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next thing we have to do is get all of the changes from the remote repositories, this will fetch down all of the latest changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now before the next step make sure that you don&#039;t have any uncommit changes, if you do finish that work, commit it, then proceed to the next step which is updating your local master.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout master&lt;br /&gt;
git pull&lt;br /&gt;
git push master github&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that your local master is up to date, and has you&#039;ve updated you master branch at github you are ready to rebase!&lt;br /&gt;
At this point we want to checkout the branch we are going to rebase, in this case wip-MDL-12345-master and then we are going to rebase origin/master which is the official Moodle master branch (and the branch our branch is based upon).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git checkout wip-MDL-12345-master&lt;br /&gt;
git rebase origin/master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once that command has completed your branch wip-MDL-12345-master will be completely up to date. Before you are done however you need to push the rebased wip-MDL-12345-master up to your github account so that its the branch the integrator sees.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git push -f github wip-MDL-12345-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now that command is just about identical to the command we used when we first pushed our branch to our github account, there is however one VERY important difference, the &#039;&#039;&#039;-f&#039;&#039;&#039; option.&lt;br /&gt;
The &#039;&#039;&#039;-f&#039;&#039;&#039; option tells git to force the push, this is required because when you rebase all of your commit id&#039;s will change and unless you tell git to force it will see that they have changed and not allow you to push your work.&lt;br /&gt;
&lt;br /&gt;
Thats it! you&#039;ve now rebased your work and the integrators will be happy again :)&lt;br /&gt;
&lt;br /&gt;
===Step 2: Rebasing wip-MDL-12345-MOODLE_20_STABLE===&lt;br /&gt;
Now that we&#039;ve rebased our work that was based upon the master branch it is time to rebase the MOODLE_20_STABLE version.&lt;br /&gt;
This step is just about identical to the previous step except we substitute &#039;&#039;master&#039;&#039; for &#039;&#039;MOODLE_20_STABLE&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/www/repositories/MOODLE_20_STABLE/moodle&lt;br /&gt;
git fetch --all --prune&lt;br /&gt;
git checkout MOODLE_20_STABLE&lt;br /&gt;
git pull&lt;br /&gt;
git push github MOODLE_20_STABLE&lt;br /&gt;
git checkout wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
git rebase origin/MOODLE_20_STABLE&lt;br /&gt;
git push -f github wip-MDL-12345-MOODLE_20_STABLE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done!&lt;br /&gt;
&lt;br /&gt;
==What to do when your work gets rejected==&lt;br /&gt;
&lt;br /&gt;
==The extra mile==&lt;br /&gt;
Now as many of you may have guessed by the time you are working on several different issues and managing several repositories the process I&#039;ve described here seems VERY repetitive. And it &#039;&#039;&#039;IS!&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you talk to any HQ developer they will tell you they deal with it in their own way, anything from scripts, to custom config files, through to virtual machine snapshots.&lt;br /&gt;
&lt;br /&gt;
Personally I have a couple of bash scripts that I wrote to help me manage my workflow.&lt;br /&gt;
&lt;br /&gt;
The first script I use I run after each weekly release and it does the following things:&lt;br /&gt;
&lt;br /&gt;
* Moves to each repository and does the following&lt;br /&gt;
*# Fetches all remote changes&lt;br /&gt;
*# Checks whether it is safe to update my local main release branches and does that if it is safe&lt;br /&gt;
*# Updates all main release branches on my github account&lt;br /&gt;
&lt;br /&gt;
The second script I run on every site that I have installed, it does the following&lt;br /&gt;
&lt;br /&gt;
* Goes to each site I have installed and does the following&lt;br /&gt;
*# Overwrites the database with a stable snapshot&lt;br /&gt;
*# Overwrites the moodle data directory with a stable snapshot taken at the same time as the database one.&lt;br /&gt;
*# Upgrades the moodle site if required&lt;br /&gt;
*# Takes a snapshot of the database and Moodle data directory.&lt;br /&gt;
&lt;br /&gt;
The third script I run whenever I start working on a new issue and it restores the stable snapshot of a sites database and moodle data directory.&lt;br /&gt;
&lt;br /&gt;
These three scripts allow me to very easily ensure I am working with the latest changes and that I can easily restore to a point I know is stable and safe.&lt;br /&gt;
&lt;br /&gt;
There was a fourth script I used to use but don&#039;t any more that also rebased any unmerged branches however I found it to be far to problematic and I prefer to do it myself so that I know exactly what is going on.&lt;br /&gt;
&lt;br /&gt;
==Useful links==&lt;br /&gt;
The following are links I found useful while learning Git.&lt;br /&gt;
&lt;br /&gt;
* [http://help.github.com Github help (http://help.github.com)] Provides EXCELLENT help tutorials that very clearly explain the basic through to the advanced.&lt;br /&gt;
* [http://cheat.errtheblog.com/s/git/ $ cheat git] This is my favourite cheat sheet, straight forward to the point, if you know the concept you&#039;ll find the answer here.&lt;br /&gt;
* [http://gitster.livejournal.com/28309.html Gitsters journal - Fun with FETCH_HEAD] David Mudrak pointed me at this entry which I found INCREDIBLY useful when reviewing other peoples work.&lt;br /&gt;
* [[Development:Git tips]] Moodle docs page with a few handy tips about using Git for Moodle development.&lt;br /&gt;
&lt;br /&gt;
I you&#039;re looking to read/buy a book on Git I&#039;d strongly recommend [http://progit.org/ Pro Git]. I certainly found that the most useful book I read.&lt;br /&gt;
&lt;br /&gt;
[[Category:Git]]&lt;/div&gt;</summary>
		<author><name>Samhemelryk</name></author>
	</entry>
</feed>