mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-25290 conversion: Converted string cache to MUC
This commit is contained in:
parent
7e8ae12a7a
commit
d90bbe6fce
@ -6302,12 +6302,6 @@ function get_string_manager($forcereload=false) {
|
||||
if ($singleton === null) {
|
||||
if (empty($CFG->early_install_lang)) {
|
||||
|
||||
if (empty($CFG->langcacheroot)) {
|
||||
$langcacheroot = $CFG->cachedir . '/lang';
|
||||
} else {
|
||||
$langcacheroot = $CFG->langcacheroot;
|
||||
}
|
||||
|
||||
if (empty($CFG->langlist)) {
|
||||
$translist = array();
|
||||
} else {
|
||||
@ -6320,7 +6314,7 @@ function get_string_manager($forcereload=false) {
|
||||
$langmenucache = $CFG->langmenucachefile;
|
||||
}
|
||||
|
||||
$singleton = new core_string_manager($CFG->langotherroot, $CFG->langlocalroot, $langcacheroot,
|
||||
$singleton = new core_string_manager($CFG->langotherroot, $CFG->langlocalroot,
|
||||
!empty($CFG->langstringcache), $translist, $langmenucache);
|
||||
|
||||
} else {
|
||||
@ -6451,10 +6445,8 @@ class core_string_manager implements string_manager {
|
||||
protected $otherroot;
|
||||
/** @var string location of all lang pack local modifications */
|
||||
protected $localroot;
|
||||
/** @var string location of on-disk cache of merged strings */
|
||||
protected $cacheroot;
|
||||
/** @var array lang string cache - it will be optimised more later */
|
||||
protected $cache = array();
|
||||
/** @var cache lang string cache - it will be optimised more later */
|
||||
protected $cache;
|
||||
/** @var int get_string() counter */
|
||||
protected $countgetstring = 0;
|
||||
/** @var int in-memory cache hits counter */
|
||||
@ -6462,7 +6454,7 @@ class core_string_manager implements string_manager {
|
||||
/** @var int on-disk cache hits counter */
|
||||
protected $countdiskcache = 0;
|
||||
/** @var bool use disk cache */
|
||||
protected $usediskcache;
|
||||
protected $usecache;
|
||||
/** @var array limit list of translations */
|
||||
protected $translist;
|
||||
/** @var string location of a file that caches the list of available translations */
|
||||
@ -6473,18 +6465,24 @@ class core_string_manager implements string_manager {
|
||||
*
|
||||
* @param string $otherroot location of downlaoded lang packs - usually $CFG->dataroot/lang
|
||||
* @param string $localroot usually the same as $otherroot
|
||||
* @param string $cacheroot usually lang dir in cache folder
|
||||
* @param bool $usediskcache use disk cache
|
||||
* @param bool $usecache use disk cache
|
||||
* @param array $translist limit list of visible translations
|
||||
* @param string $menucache the location of a file that caches the list of available translations
|
||||
*/
|
||||
public function __construct($otherroot, $localroot, $cacheroot, $usediskcache, $translist, $menucache) {
|
||||
public function __construct($otherroot, $localroot, $usecache, $translist, $menucache) {
|
||||
$this->otherroot = $otherroot;
|
||||
$this->localroot = $localroot;
|
||||
$this->cacheroot = $cacheroot;
|
||||
$this->usediskcache = $usediskcache;
|
||||
$this->usecache = $usecache;
|
||||
$this->translist = $translist;
|
||||
$this->menucache = $menucache;
|
||||
|
||||
if ($this->usecache) {
|
||||
// We can use a proper cache, establish the cache using the 'String cache' definition.
|
||||
$this->cache = cache::make('core', 'string');
|
||||
} else {
|
||||
// We only want a cache for the length of the request, create a static cache.
|
||||
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6531,18 +6529,13 @@ class core_string_manager implements string_manager {
|
||||
$component = $plugintype . '_' . $pluginname;
|
||||
}
|
||||
|
||||
if (!$disablecache and !$disablelocal) {
|
||||
// try in-memory cache first
|
||||
if (isset($this->cache[$lang][$component])) {
|
||||
$this->countmemcache++;
|
||||
return $this->cache[$lang][$component];
|
||||
}
|
||||
$cachekey = $lang.'/'.$component;
|
||||
|
||||
// try on-disk cache then
|
||||
if ($this->usediskcache and file_exists($this->cacheroot . "/$lang/$component.php")) {
|
||||
if (!$disablecache and !$disablelocal) {
|
||||
$string = $this->cache->get($cachekey);
|
||||
if ($string) {
|
||||
$this->countdiskcache++;
|
||||
include($this->cacheroot . "/$lang/$component.php");
|
||||
return $this->cache[$lang][$component];
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6625,11 +6618,7 @@ class core_string_manager implements string_manager {
|
||||
if (!$disablelocal) {
|
||||
// now we have a list of strings from all possible sources. put it into both in-memory and on-disk
|
||||
// caches so we do not need to do all this merging and dependencies resolving again
|
||||
$this->cache[$lang][$component] = $string;
|
||||
if ($this->usediskcache) {
|
||||
check_dir_exists("$this->cacheroot/$lang");
|
||||
file_put_contents("$this->cacheroot/$lang/$component.php", "<?php \$this->cache['$lang']['$component'] = ".var_export($string, true).";");
|
||||
}
|
||||
$this->cache->set($cachekey, $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
@ -6708,12 +6697,12 @@ class core_string_manager implements string_manager {
|
||||
// parentlanguage is a special string, undefined means use English if not defined
|
||||
return 'en';
|
||||
}
|
||||
if ($this->usediskcache) {
|
||||
if ($this->usecache) {
|
||||
// maybe the on-disk cache is dirty - let the last attempt be to find the string in original sources,
|
||||
// do NOT write the results to disk cache because it may end up in race conditions see MDL-31904
|
||||
$this->usediskcache = false;
|
||||
$this->usecache = false;
|
||||
$string = $this->load_component_strings($component, $lang, true);
|
||||
$this->usediskcache = true;
|
||||
$this->usecache = true;
|
||||
}
|
||||
if (!isset($string[$identifier])) {
|
||||
// the string is still missing - should be fixed by developer
|
||||
@ -7005,10 +6994,7 @@ class core_string_manager implements string_manager {
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
// clear the on-disk disk with aggregated string files
|
||||
fulldelete($this->cacheroot);
|
||||
|
||||
// clear the in-memory cache of loaded strings
|
||||
$this->cache = array();
|
||||
$this->cache->purge();
|
||||
|
||||
if (!$phpunitreset) {
|
||||
// Increment the revision counter.
|
||||
|
Loading…
x
Reference in New Issue
Block a user