MDL-22052 Improved get_string caching - dirty on-disk cache detection

If the string is not found, core_string_manager tries to re-fetch master
sources. This prevents false debugging messages in case when the on-disk
cache is dirty. Thanks to Eloy, Tim and Petr for the ideas.
This commit is contained in:
David Mudrak 2010-06-25 09:40:34 +00:00
parent 43240ea13f
commit 477912aec1

View file

@ -5786,9 +5786,10 @@ class core_string_manager implements string_manager {
* Load all strings for one component * Load all strings for one component
* @param string $component The module the string is associated with * @param string $component The module the string is associated with
* @param string $lang * @param string $lang
* @param bool $disablecache Do not use caches, force fetching the strings from sources
* @return array of all string for given component and lang * @return array of all string for given component and lang
*/ */
public function load_component_strings($component, $lang) { public function load_component_strings($component, $lang, $disablecache=false) {
global $CFG; global $CFG;
list($plugintype, $pluginname) = normalize_component($component); list($plugintype, $pluginname) = normalize_component($component);
@ -5798,6 +5799,7 @@ class core_string_manager implements string_manager {
$component = $plugintype . '_' . $pluginname; $component = $plugintype . '_' . $pluginname;
} }
if (!$disablecache) {
// try in-memory cache first // try in-memory cache first
if (isset($this->cache[$lang][$component])) { if (isset($this->cache[$lang][$component])) {
$this->countmemcache++; $this->countmemcache++;
@ -5810,6 +5812,7 @@ class core_string_manager implements string_manager {
include($this->cacheroot . "/$lang/$component.php"); include($this->cacheroot . "/$lang/$component.php");
return $this->cache[$lang][$component]; return $this->cache[$lang][$component];
} }
}
// no cache found - let us merge all possible sources of the strings // no cache found - let us merge all possible sources of the strings
if ($plugintype === 'core') { if ($plugintype === 'core') {
@ -5911,7 +5914,7 @@ class core_string_manager implements string_manager {
return false; return false;
} }
$lang = current_language(); $lang = current_language();
$string = $this->load_component_strings($component, $lang); $string = $this->load_component_strings($component, $lang, true);
return isset($string[$identifier]); return isset($string[$identifier]);
} }
@ -5968,9 +5971,16 @@ class core_string_manager implements string_manager {
// parentlanguage is a special string, undefined means use English if not defined // parentlanguage is a special string, undefined means use English if not defined
return 'en'; return 'en';
} }
if ($this->usediskcache) {
// maybe the on-disk cache is dirty - let the last attempt be to find the string in original sources
$string = $this->load_component_strings($component, $lang, true);
}
if (!isset($string[$identifier])) {
// the string is still missing - should be fixed by developer
debugging("Invalid get_string() identifier: '$identifier' or component '$component'", DEBUG_DEVELOPER); debugging("Invalid get_string() identifier: '$identifier' or component '$component'", DEBUG_DEVELOPER);
return "[[$identifier]]"; return "[[$identifier]]";
} }
}
$string = $string[$identifier]; $string = $string[$identifier];