Permalink
Browse files

MDL-25290 cache: Cache API integration with core

  • Loading branch information...
1 parent 8139ad1 commit d6a1f63bddce5bd9df0c523fbc911462f8deef67 Sam Hemelryk committed Sep 10, 2012
Showing with 199 additions and 0 deletions.
  1. +10 −0 admin/settings/server.php
  2. +10 −0 lang/en/admin.php
  3. +84 −0 lang/en/cache.php
  4. +34 −0 lib/db/caches.php
  5. +35 −0 lib/moodlelib.php
  6. +9 −0 lib/setup.php
  7. +3 −0 phpunit.xml.dist
  8. +8 −0 theme/base/style/admin.css
  9. +6 −0 theme/base/style/core.css
@@ -216,6 +216,16 @@
array( '0' => new lang_string('no'),
'1' => new lang_string('yes'))));
*/
+
+$ADMIN->add('server', new admin_category('cache', new lang_string('caching', 'cache')));
+$ADMIN->add('cache', new admin_externalpage('cacheconfig', get_string('cacheconfig', 'cache'), new moodle_url('/cache/admin.php')));
+$ADMIN->add('cache', new admin_externalpage('cachetestperformance', get_string('testperformance', 'cache'), new moodle_url('/cache/testperformance.php')));
+foreach (get_plugin_list_with_file('cache', 'settings.php') as $plugin => $path) {
+ $settings = new admin_settingpage('cache_'.$plugin.'_settings', new lang_string('pluginname', 'cache_'.$plugin));
+ require_once($path);
+ $ADMIN->add('cache', $settings);
+}
+
$ADMIN->add('server', $temp);
View
@@ -1072,3 +1072,13 @@
$string['xmlrpcrecommended'] = 'The xmlrpc extension is needed for hub communication, and useful for web services and Moodle networking';
$string['yuicomboloading'] = 'YUI combo loading';
$string['ziprequired'] = 'The Zip PHP extension is now required by Moodle, info-ZIP binaries or PclZip library are not used anymore.';
+
+
+$string['caching'] = 'Caching';
+$string['cachesettings'] = 'Cache settings';
+$string['cacherequest'] = 'Request cache';
+$string['cacherequesthelp'] = 'User specific cache that expires when the request is complete. Designed to replace areas where we are using the static stores.';
+$string['cachesession'] = 'Session cache';
+$string['cachesessionhelp'] = 'User specific cache that expires when the users session ends. Designed to aleviate session bloat/strain.';
+$string['cacheapplication'] = 'Application cache';
+$string['cacheapplicationhelp'] = ' Cached items are shared amoung all users and expire by a determined ttl.';
View
@@ -0,0 +1,84 @@
+<?php
+
+$string['actions'] = 'Actions';
+$string['addinstance'] = 'Add instance';
+$string['addstore'] = 'Add {$a} store';
+$string['addstoresuccess'] = 'Successfully added a new {$a} store.';
+$string['area'] = 'Area';
+$string['caching'] = 'Caching';
+$string['cacheadmin'] = 'Cache administration';
+$string['cacheconfig'] = 'Configuration';
+$string['cachedef_config'] = 'Config settings';
+$string['cachedef_databasemeta'] = 'Database meta information';
+$string['cachedef_eventinvalidation'] = 'Event invalidation';
+$string['cachedef_locking'] = 'Locking';
+$string['cachedef_string'] = 'Language string cache';
+$string['component'] = 'Component';
+$string['confirmstoredeletion'] = 'Confirm store deletion';
+$string['defaultmappings'] = 'Default mappings';
+$string['defaultmappings_help'] = 'These are the default stores that will be used if you don\'t map one or more stores to the cache definition.';
+$string['defaultstoreactions'] = 'Default stores cannot be modified';
+$string['default_application'] = 'Default application store';
+$string['default_locking'] = 'Default store for locking';
+$string['default_request'] = 'Default request store';
+$string['default_session'] = 'Default session store';
+$string['definition'] = 'Definition';
+$string['definitionsummaries'] = 'Definition summaries';
+$string['delete'] = 'Delete';
+$string['deletestore'] = 'Delete store';
+$string['deletestoreconfirmation'] = 'Are you sure you want to delete the "{$a}" store?';
+$string['deletestorehasmappings'] = 'You cannot delete this store because it has mappings. Please delete all mappings before deleting the store';
+$string['deletestoresuccess'] = 'Successfully deleted the cache store';
+$string['editmappings'] = 'Edit mappings';
+$string['editstore'] = 'Edit store';
+$string['editstoresuccess'] = 'Succesfully edited the cache store.';
+$string['editdefinitionmappings'] = '{$a} definition store mappings';
+$string['ex_configcannotsave'] = 'Unable to save the cache config to file.';
+$string['ex_unabletolock'] = 'Unable to acquire a lock for caching.';
+$string['gethit'] = 'Get - Hit';
+$string['getmiss'] = 'Get - Miss';
+$string['invalidplugin'] = 'Invalid plugin';
+$string['invalidstore'] = 'Invalid cache store provided';
+$string['mappings'] = 'Store mappings';
+$string['mappingdefault'] = '(default)';
+$string['mappingprimary'] = 'Primary store';
+$string['mappingfinal'] = 'Final store';
+$string['mode'] = 'Mode';
+$string['modes'] = 'Modes';
+$string['mode_1'] = 'Application';
+$string['mode_2'] = 'Session';
+$string['mode_4'] = 'Request';
+$string['none'] = 'None';
+$string['plugin'] = 'Plugin';
+$string['pluginsummaries'] = 'Plugin summaries';
+$string['purge'] = 'Purge';
+$string['requestcount'] = 'Test with {$a} requests';
+$string['rescandefinitions'] = 'Rescan definitions';
+$string['result'] = 'Result';
+$string['set'] = 'Set';
+$string['storeconfiguration'] = 'Store configuration';
+$string['storename'] = 'Store name';
+$string['storename_help'] = 'This sets the store name. It is used to identify the store within the system and can only consist of a-z A-Z 0-9 -_ and spaces. It also must be unique. If you attempt to use a name that has already been used you will recieve an error.';
+$string['storenamealreadyused'] = 'You must choose a unique name for this store.';
+$string['storenameinvalid'] = 'Invalid store name. You can only use a-z A-Z 0-9 -_ and spaces.';
+$string['storeperformance'] = 'Cache store performance reporting - {$a} unique requests per operation.';
+$string['storeready'] = 'Ready';
+$string['storeresults_application'] = 'Store requests when used as an application cache.';
+$string['storeresults_request'] = 'Store requests when used as a request cache.';
+$string['storeresults_session'] = 'Store requests when used as a session cache.';
+$string['stores'] = 'Stores';
+$string['store_default_application'] = 'Default file store for application caches';
+$string['store_default_locking'] = 'Default file store for locking';
+$string['store_default_request'] = 'Default static store for request caches';
+$string['store_default_session'] = 'Default session store for session caches';
+$string['storesummaries'] = 'Store summaries';
+$string['supports'] = 'Supports';
+$string['supports_multipleidentifiers'] = 'multiple identifiers';
+$string['supports_dataguarantee'] = 'data guarantee';
+$string['supports_nativettl'] = 'ttl';
+$string['supports_nativelocking'] = 'locking';
+$string['supports_keyawareness'] = 'key awareness';
+$string['tested'] = 'Tested';
+$string['testperformance'] = 'Test performance';
+$string['unsupportedmode'] = 'Unsupported mode';
+$string['untestable'] = 'Untestable';
View
@@ -0,0 +1,34 @@
+<?php
+
+$definitions = array(
+ // Default cache for locking
+ 'locking' => array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'mappingsonly' => true,
+ ),
+ 'string' => array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'component' => 'core',
+ 'area' => 'string',
+ 'persistent' => true,
+ 'persistentmaxsize' => 3
+ ),
+ 'databasemeta' => array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'requireidentifiers' => array(
+ 'dbfamily'
+ ),
+ 'persistent' => true,
+ 'persistentmaxsize' => 2
+ ),
+ 'config' => array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'persistent' => true
+ ),
+ // Event invalidation cache
+ 'eventinvalidation' => array(
+ 'mode' => cache_store::MODE_APPLICATION,
+ 'persistent' => true,
+ 'requiredataguarantee' => true
+ )
+);
View
@@ -1498,6 +1498,8 @@ function purge_all_caches() {
get_string_manager()->reset_caches();
textlib::reset_caches();
+ cache_helper::purge_all();
+
// purge all other caches: rss, simplepie, etc.
remove_dir($CFG->cachedir.'', true);
@@ -7906,6 +7908,7 @@ function get_core_subsystems() {
'block' => 'blocks',
'blog' => 'blog',
'bulkusers' => NULL,
+ 'cache' => 'cache',
'calendar' => 'calendar',
'cohort' => 'cohort',
'condition' => NULL,
@@ -8004,6 +8007,7 @@ function get_plugin_types($fullpaths=true) {
'qformat' => 'question/format',
'plagiarism' => 'plagiarism',
'tool' => $CFG->admin.'/tool',
+ 'cache' => 'cache/stores',
'theme' => 'theme', // this is a bit hacky, themes may be in $CFG->themedir too
);
@@ -10425,6 +10429,37 @@ function get_performance_info() {
$info['txt'] .= 'rcache: '.
"{$rcache->hits}/{$rcache->misses} ";
}*/
+
+ if ($stats = cache_helper::get_stats()) {
+ $html = '<span class="cachesused">';
+ $html .= '<span class="cache-stats-heading">Caches interaction by definition then store</span>';
+ $text = 'Caches used (hits/misses/sets): ';
+ $hits = 0;
+ $misses = 0;
+ $sets = 0;
+ foreach ($stats as $definition => $stores) {
+ $html .= '<span class="cache-definition-stats">'.$definition.'</span>';
+ $text .= "$definition {";
+ foreach ($stores as $store => $data) {
+ $hits += $data['hits'];
+ $misses += $data['misses'];
+ $sets += $data['sets'];
+ $text .= "$store($data[hits]/$data[misses]/$data[sets]) ";
+ $html .= "<span class='cache-store-stats'>$store: $data[hits] / $data[misses] / $data[sets]</span>";
+ }
+ $text .= '} ';
+ }
+ $html .= "<span class='cache-total-stats'>Total Hits / Misses / Sets : $hits / $misses / $sets</span>";
+ $html .= '</span> ';
+ $info['cachesused'] = "$hits / $misses / $sets";
+ $info['html'] .= $html;
+ $info['txt'] .= $text.'. ';
+ } else {
+ $info['cachesused'] = '0 / 0 / 0';
+ $info['html'] .= '<span class="cachesused">Caches used (hits/misses/sets): 0/0/0</span>';
+ $info['txt'] .= 'Caches used (hits/misses/sets): 0/0/0 ';
+ }
+
$info['html'] = '<div class="performanceinfo siteinfo">'.$info['html'].'</div>';
return $info;
}
View
@@ -138,6 +138,14 @@
define('PHPUNIT_TEST', false);
}
+// When set to true MUC (Moodle caching) will not use any of the defined or default stores.
+// The Cache API will continue to function however this will force the use of the cache_store_dummy so all requests
+// will be interacting with a static property and will never go to the proper cache stores.
+// Useful if you need to avoid the stores for one reason or another.
+if (!defined('NO_CACHE_STORES')) {
+ define('NO_CACHE_STORES', false);
+}
+
// Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
// This is a quick hack. Ideally we should ask the admin for a value. See MDL-22625 for more on this.
if (function_exists('date_default_timezone_set') and function_exists('date_default_timezone_get')) {
@@ -468,6 +476,7 @@
require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
require_once($CFG->libdir .'/modinfolib.php'); // Cached information on course-module instances
+require_once($CFG->dirroot.'/cache/lib.php'); // Cache API
// make sure PHP is not severly misconfigured
setup_validate_php_configuration();
View
@@ -66,6 +66,9 @@
<directory suffix="_test.php">question/tests</directory>
<directory suffix="_test.php">question/type/tests</directory>
</testsuite>
+ <testsuite name="core_cache">
+ <directory suffix="_test.php">cache/tests</directory>
+ </testsuite>
<!--Plugin suites: use admin/tool/phpunit/cli/util.php to build phpunit.xml from phpunit.xml.dist with up-to-date list of plugins in current install-->
<!--@plugin_suites_start@-->
@@ -256,3 +256,11 @@
#page-admin-mnet-peers .box.deletedhosts {margin-bottom:1em;font-size:80%;}
#page-admin-mnet-peers .mform .certdetails {background-color:white;}
#page-admin-mnet-peers .mform .deletedhostinfo {background-color:#ffd3d9;border 2px solid #eeaaaa;padding:4px;margin-bottom:5px;}
+
+#core-cache-plugin-summaries table,
+#core-cache-store-summaries table {width:100%;}
+#core-cache-definition-summaries table,
+#core-cache-mode-mappings table {margin:0 auto;}
+#core-cache-store-summaries .default-store td {color:#333;font-style: italic;}
+#core-cache-rescan-definitions,
+#core-cache-mode-mappings .edit-link {margin-top:0.5em;text-align:center;}
@@ -184,6 +184,12 @@ a.skip:active {position: static;display: block;}
#page-footer .validators ul {margin:0px;padding:0px;list-style-type:none;}
#page-footer .validators ul li {display:inline;margin-right:10px;margin-left:10px;}
+.performanceinfo .cachesused {margin-top:1em;}
+.performanceinfo .cachesused .cache-stats-heading {font-weight: bold;text-decoration: underline;font-size:110%;}
+.performanceinfo .cachesused .cache-definition-stats {font-weight:bold;margin-top:0.3em;}
+.performanceinfo .cachesused .cache-store-stats {text-indent: 1em;}
+.performanceinfo .cachesused .cache-total-stats {font-weight:bold;margin-top:0.3em;}
+
/**
* Tabs
*/

0 comments on commit d6a1f63

Please sign in to comment.