Skip to content
Browse files

MDL-34401 Replace ad-hoc plugin request caches with proper applicatio…

…n 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.
  • Loading branch information...
1 parent b8a6f26 commit ad3ed98b05d5d5ec5f394bb81f3a808e9ea4f929 @mudrd8mz mudrd8mz committed Feb 12, 2013
Showing with 89 additions and 13 deletions.
  1. +3 −0 admin/blocks.php
  2. +3 −0 admin/filters.php
  3. +3 −0 admin/modules.php
  4. +3 −0 admin/portfolio.php
  5. +3 −0 admin/repository.php
  6. +3 −0 filter/manage.php
  7. +55 −0 lib/db/caches.php
  8. +6 −0 lib/moodlelib.php
  9. +6 −12 lib/pluginlib.php
  10. +3 −0 user/portfolio.php
  11. +1 −1 version.php
View
3 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()) {
View
3 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.
View
3 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()) {
View
3 admin/portfolio.php
@@ -43,6 +43,9 @@
$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
View
3 admin/repository.php
@@ -61,6 +61,9 @@
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
View
3 filter/manage.php
@@ -36,6 +36,9 @@
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)) {
View
55 lib/db/caches.php
@@ -136,4 +136,59 @@
'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,
+ ),
+
);
View
6 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;
View
18 lib/pluginlib.php
@@ -2479,8 +2479,7 @@ public function get_dir() {
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 @@ public function get_uninstall_url() {
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 @@ public function get_uninstall_url() {
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 @@ public function get_uninstall_url() {
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 @@ public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $h
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 @@ public function is_enabled() {
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');
View
3 user/portfolio.php
@@ -57,6 +57,9 @@
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");
View
2 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

0 comments on commit ad3ed98

Please sign in to comment.
Something went wrong with that request. Please try again.