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.
This commit is contained in:
David Mudrák 2013-02-12 18:24:56 +01:00
parent b8a6f26ee3
commit ad3ed98b05
11 changed files with 89 additions and 13 deletions

View File

@ -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 File

@ -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 File

@ -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 File

@ -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

View File

@ -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

View File

@ -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)) {

View File

@ -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,
),
);

View File

@ -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 File

@ -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');

View File

@ -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");

View File

@ -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