From ad3ed98b05d5d5ec5f394bb81f3a808e9ea4f929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Tue, 12 Feb 2013 18:24:56 +0100 Subject: [PATCH] MDL-34401 Replace ad-hoc plugin request caches with proper application caches Data cached in these caches change only at well defined places (during need for upgrade checks, at the plugin management screen etc). So it makes sense to use proper application caches instead of request caches. This saves couple of database queries at almost every page in Moodle. --- admin/blocks.php | 3 +++ admin/filters.php | 3 +++ admin/modules.php | 3 +++ admin/portfolio.php | 3 +++ admin/repository.php | 3 +++ filter/manage.php | 3 +++ lib/db/caches.php | 55 ++++++++++++++++++++++++++++++++++++++++++++ lib/moodlelib.php | 6 +++++ lib/pluginlib.php | 18 +++++---------- user/portfolio.php | 3 +++ version.php | 2 +- 11 files changed, 89 insertions(+), 13 deletions(-) diff --git a/admin/blocks.php b/admin/blocks.php index 5b5c3a17be9..f2017b912a1 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -30,6 +30,9 @@ $strprotect = get_string('blockprotect', 'admin'); $strunprotect = get_string('blockunprotect', 'admin'); + // Purge all caches related to blocks administration. + cache::make('core', 'plugininfo_block')->purge(); + /// If data submitted, then process and store. if (!empty($hide) && confirm_sesskey()) { diff --git a/admin/filters.php b/admin/filters.php index 0dbb4150d59..6c585046ab9 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -44,6 +44,9 @@ $returnurl = "$CFG->wwwroot/$CFG->admin/filters.php"; admin_externalpage_setup('managefilters'); + // Purge all caches related to filter administration. + cache::make('core', 'plugininfo_filter')->purge(); + $filters = filter_get_global_states(); // In case any new filters have been installed, but not put in the table yet. diff --git a/admin/modules.php b/admin/modules.php index 3ad0a72cc6e..33d2fbbff4e 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -29,6 +29,9 @@ $stractivitymodule = get_string("activitymodule"); $strshowmodulecourse = get_string('showmodulecourse'); + // Purge all caches related to activity modules administration. + cache::make('core', 'plugininfo_mod')->purge(); + /// If data submitted, then process and store. if (!empty($hide) and confirm_sesskey()) { diff --git a/admin/portfolio.php b/admin/portfolio.php index 16aa66183ed..1811f5f774f 100644 --- a/admin/portfolio.php +++ b/admin/portfolio.php @@ -43,6 +43,9 @@ $configstr = get_string('manageportfolios', 'portfolio'); $return = true; // direct back to the main page +// Purge all caches related to portfolio administration. +cache::make('core', 'plugininfo_portfolio')->purge(); + /** * Helper function that generates a moodle_url object * relevant to the portfolio diff --git a/admin/repository.php b/admin/repository.php index a4cdd220b92..26f1ba46ced 100644 --- a/admin/repository.php +++ b/admin/repository.php @@ -61,6 +61,9 @@ if (!empty($action)) { require_sesskey(); } +// Purge all caches related to repositories administration. +cache::make('core', 'plugininfo_repository')->purge(); + /** * Helper function that generates a moodle_url object * relevant to the repository diff --git a/filter/manage.php b/filter/manage.php index 89ba5ca8ffc..0bea014ba08 100644 --- a/filter/manage.php +++ b/filter/manage.php @@ -36,6 +36,9 @@ require_login($course, false, $cm); require_capability('moodle/filter:manage', $context); $PAGE->set_context($context); +// Purge all caches related to filter administration. +cache::make('core', 'plugininfo_filter')->purge(); + $args = array('contextid'=>$contextid); $baseurl = new moodle_url('/filter/manage.php', $args); if (!empty($forfilter)) { diff --git a/lib/db/caches.php b/lib/db/caches.php index 9ba6f5abb5b..795342dfca9 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -136,4 +136,59 @@ $definitions = array( 'persistent' => true, 'persistentmaxsize' => 2, ), + + // Cache used by the {@link plugininfo_base} class. + 'plugininfo_base' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 2, + ), + + // Cache used by the {@link plugininfo_mod} class. + 'plugininfo_mod' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 1, + ), + + // Cache used by the {@link plugininfo_block} class. + 'plugininfo_block' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 1, + ), + + // Cache used by the {@link plugininfo_filter} class. + 'plugininfo_filter' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 1, + ), + + // Cache used by the {@link plugininfo_repository} class. + 'plugininfo_repository' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 1, + ), + + // Cache used by the {@link plugininfo_portfolio} class. + 'plugininfo_portfolio' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'persistent' => true, + 'persistentmaxsize' => 1, + ), + ); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 1fe0511463c..a53a8de8fb8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -9143,6 +9143,12 @@ function moodle_needs_upgrading() { // and new plugins can be detected. cache::make('core', 'plugintypes')->purge(); cache::make('core', 'pluginlist')->purge(); + cache::make('core', 'plugininfo_base')->purge(); + cache::make('core', 'plugininfo_mod')->purge(); + cache::make('core', 'plugininfo_block')->purge(); + cache::make('core', 'plugininfo_filter')->purge(); + cache::make('core', 'plugininfo_repository')->purge(); + cache::make('core', 'plugininfo_portfolio')->purge(); // Check the main version first. $version = null; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 298b3a26fff..f56a5a519b3 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2479,8 +2479,7 @@ abstract class plugininfo_base { protected function get_version_from_config_plugins($plugin, $disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_base', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_base'); $pluginversions = $cache->get('versions_db'); @@ -2641,8 +2640,7 @@ class plugininfo_block extends plugininfo_base { protected static function get_blocks_info($disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_block', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_block'); $blocktypes = $cache->get('blocktypes'); @@ -2786,8 +2784,7 @@ class plugininfo_filter extends plugininfo_base { protected static function get_global_states($disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_filter', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_filter'); $globalstates = $cache->get('globalstates'); @@ -2958,8 +2955,7 @@ class plugininfo_mod extends plugininfo_base { protected static function get_modules_info($disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_mod', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_mod'); $modulesinfo = $cache->get('modulesinfo'); @@ -3220,8 +3216,7 @@ class plugininfo_repository extends plugininfo_base { protected static function get_enabled_repositories($disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_repository', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_repository'); $enabled = $cache->get('enabled'); @@ -3259,8 +3254,7 @@ class plugininfo_portfolio extends plugininfo_base { protected static function get_enabled_portfolios($disablecache=false) { global $DB; - $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core_plugin', 'plugininfo_portfolio', - array(), array('simplekeys' => true, 'simpledata' => true)); + $cache = cache::make('core', 'plugininfo_portfolio'); $enabled = $cache->get('enabled'); diff --git a/user/portfolio.php b/user/portfolio.php index 653131e365d..a84935ce458 100644 --- a/user/portfolio.php +++ b/user/portfolio.php @@ -57,6 +57,9 @@ $display = true; // set this to false in the conditions to stop processing require_login($course, false); +// Purge all caches related to portfolio administration. +cache::make('core', 'plugininfo_portfolio')->purge(); + $PAGE->set_url($url); $PAGE->set_context(context_user::instance($user->id)); $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); diff --git a/version.php b/version.php index 9682890f80e..5a61b9c1b99 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013030800.02; // YYYYMMDD = weekly release date of this DEV branch +$version = 2013030800.03; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes