Skip to content

Commit

Permalink
MDL-41019 improve language caching
Browse files Browse the repository at this point in the history
Includes:
* no more hacky reloads, everything is written only once and kept until cache reset
* lang menu list is now cached in MUC
* both string and lang menu caches are compatible with local caches on cluster nodes
* config-dist.php cleanup
  • Loading branch information
skodak committed Aug 11, 2013
1 parent 99a9d8d commit 598a82c
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 178 deletions.
21 changes: 1 addition & 20 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,25 +365,6 @@
// Locking resolves race conditions and is strongly recommended for production servers.
// $CFG->preventfilelocking = false;
//
// If $CFG->langstringcache is enabled (which should always be in production
// environment), Moodle keeps aggregated strings in its own internal format
// optimised for performance. By default, this on-disk cache is created in
// $CFG->cachedir/lang. In cluster environment, you may wish to specify
// an alternative location of this cache so that each web server in the cluster
// uses its own local cache and does not need to access the shared dataroot.
// Make sure that the web server process has write permission to this location
// and that it has permission to remove the folder, too (so that the cache can
// be pruned).
//
// $CFG->langcacheroot = '/var/www/moodle/htdocs/altcache/lang';
//
// If $CFG->langcache is enabled (which should always be in production
// environment), Moodle stores the list of available languages in a cache file.
// By default, the file $CFG->dataroot/languages is used. You may wish to
// specify an alternative location of this cache file.
//
// $CFG->langmenucachefile = '/var/www/moodle/htdocs/altcache/languages';
//
// Site default language can be set via standard administration interface. If you
// want to have initial error messages for eventual database connection problems
// localized too, you have to set your language code here.
Expand Down Expand Up @@ -488,7 +469,7 @@
// Prevent JS caching
// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
//
// Prevent core_string_manager on-disk cache
// Prevent core_string_manager application caching
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
//
// When working with production data on test servers, no emails or other messages
Expand Down
1 change: 1 addition & 0 deletions lang/en/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$string['cachedef_eventinvalidation'] = 'Event invalidation';
$string['cachedef_groupdata'] = 'Course group information';
$string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content';
$string['cachedef_langmenu'] = 'List of available languages';
$string['cachedef_locking'] = 'Locking';
$string['cachedef_observers'] = 'Event observers';
$string['cachedef_plugininfo_base'] = 'Plugin info - base';
Expand Down
1 change: 0 additions & 1 deletion lib/classes/string_manager_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public function get_string($identifier, $component = '', $a = null, $lang = null
if (isset($string['parentlanguage'])) {
$parent = $string['parentlanguage'];
}
unset($string);
}
}

Expand Down
255 changes: 114 additions & 141 deletions lib/classes/string_manager_standard.php

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion lib/db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
$definitions = array(

// Used to store processed lang files.
// The keys used are the component of the string file.
// The keys used are the revision, lang and component of the string file.
// The persistent max size has been based upon student access of the site.
// NOTE: this data may be safely stored in local caches on cluster nodes.
'string' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
Expand All @@ -39,6 +40,15 @@
'persistentmaxsize' => 30
),

// Used to store cache of all available translations.
// NOTE: this data may be safely stored in local caches on cluster nodes.
'langmenu' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'persistent' => true,
),

// Used to store database meta information.
// The database meta information includes information about tables and there columns.
// Its keys are the table names.
Expand Down
9 changes: 1 addition & 8 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6635,14 +6635,7 @@ function get_string_manager($forcereload=false) {
$translist = explode(',', $CFG->langlist);
}

if (empty($CFG->langmenucachefile)) {
$langmenucache = $CFG->cachedir . '/languages';
} else {
$langmenucache = $CFG->langmenucachefile;
}

$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot,
!empty($CFG->langstringcache), $translist, $langmenucache);
$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot, $translist);

} else {
$singleton = new core_string_manager_install();
Expand Down
3 changes: 1 addition & 2 deletions lib/setuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ function get_exception_info($ex) {
// Remove some absolute paths from message and debugging info.
$searches = array();
$replaces = array();
$cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir',
'langmenucachefile', 'langcacheroot', 'dataroot', 'dirroot');
$cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir', 'dataroot', 'dirroot');
foreach ($cfgnames as $cfgname) {
if (property_exists($CFG, $cfgname)) {
$searches[] = $CFG->$cfgname;
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ information provided here is intended especially for developers.
* New $CFG->localcachedir setting useful for cluster nodes. Admins have to update X-Sendfile aliases if used.
* MS SQL Server drivers are now using NVARCHAR(MAX) instead of NTEXT and VARBINARY(MAX) instead of IMAGE,
this change should be fully transparent and it should help significantly with add-on compatibility.
* The string manager classes were renamed. Note that they should not be modified or used directly,
always use get_string_manager() to get instance of the string manager.

DEPRECATIONS:
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices
Expand Down
7 changes: 2 additions & 5 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3452,11 +3452,8 @@ function get_formatted_help_string($identifier, $component, $ajax = false) {
global $CFG, $OUTPUT;
$sm = get_string_manager();

if (!$sm->string_exists($identifier, $component) ||
!$sm->string_exists($identifier . '_help', $component)) {
// Strings in the on-disk cache may be dirty - try to rebuild it and check again.
$sm->load_component_strings($component, current_language(), true);
}
// Do not rebuild caches here!
// Devs need to learn to purge all caches after any change or disable $CFG->langstringcache.

$data = new stdClass();

Expand Down

0 comments on commit 598a82c

Please sign in to comment.