Moodle release 3.3.8
[moodle.git] / cache / classes / helper.php
blobbddc8e4ebd008438d1969f349a9346a8c59a1d0a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Cache helper class
20 * This file is part of Moodle's cache API, affectionately called MUC.
21 * It contains the components that are requried in order to use caching.
23 * @package core
24 * @category cache
25 * @copyright 2012 Sam Hemelryk
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 defined('MOODLE_INTERNAL') || die();
31 /**
32 * The cache helper class.
34 * The cache helper class provides common functionality to the cache API and is useful to developers within to interact with
35 * the cache API in a general way.
37 * @package core
38 * @category cache
39 * @copyright 2012 Sam Hemelryk
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class cache_helper {
44 /**
45 * Statistics gathered by the cache API during its operation will be used here.
46 * @static
47 * @var array
49 protected static $stats = array();
51 /**
52 * The instance of the cache helper.
53 * @var cache_helper
55 protected static $instance;
57 /**
58 * The site identifier used by the cache.
59 * Set the first time get_site_identifier is called.
60 * @var string
62 protected static $siteidentifier = null;
64 /**
65 * Returns true if the cache API can be initialised before Moodle has finished initialising itself.
67 * This check is essential when trying to cache the likes of configuration information. It checks to make sure that the cache
68 * configuration file has been created which allows use to set up caching when ever is required.
70 * @return bool
72 public static function ready_for_early_init() {
73 return cache_config::config_file_exists();
76 /**
77 * Returns an instance of the cache_helper.
79 * This is designed for internal use only and acts as a static store.
80 * @staticvar null $instance
81 * @return cache_helper
83 protected static function instance() {
84 if (is_null(self::$instance)) {
85 self::$instance = new cache_helper();
87 return self::$instance;
90 /**
91 * Constructs an instance of the cache_helper class. Again for internal use only.
93 protected function __construct() {
94 // Nothing to do here, just making sure you can't get an instance of this.
97 /**
98 * Used as a data store for initialised definitions.
99 * @var array
101 protected $definitions = array();
104 * Used as a data store for initialised cache stores
105 * We use this because we want to avoid establishing multiple instances of a single store.
106 * @var array
108 protected $stores = array();
111 * Returns the class for use as a cache loader for the given mode.
113 * @param int $mode One of cache_store::MODE_
114 * @return string
115 * @throws coding_exception
117 public static function get_class_for_mode($mode) {
118 switch ($mode) {
119 case cache_store::MODE_APPLICATION :
120 return 'cache_application';
121 case cache_store::MODE_REQUEST :
122 return 'cache_request';
123 case cache_store::MODE_SESSION :
124 return 'cache_session';
126 throw new coding_exception('Unknown cache mode passed. Must be one of cache_store::MODE_*');
130 * Returns the cache stores to be used with the given definition.
131 * @param cache_definition $definition
132 * @return array
134 public static function get_cache_stores(cache_definition $definition) {
135 $instance = cache_config::instance();
136 $stores = $instance->get_stores_for_definition($definition);
137 $stores = self::initialise_cachestore_instances($stores, $definition);
138 return $stores;
142 * Internal function for initialising an array of stores against a given cache definition.
144 * @param array $stores
145 * @param cache_definition $definition
146 * @return cache_store[]
148 protected static function initialise_cachestore_instances(array $stores, cache_definition $definition) {
149 $return = array();
150 $factory = cache_factory::instance();
151 foreach ($stores as $name => $details) {
152 $store = $factory->create_store_from_config($name, $details, $definition);
153 if ($store !== false) {
154 $return[] = $store;
157 return $return;
161 * Returns a cache_lock instance suitable for use with the store.
163 * @param cache_store $store
164 * @return cache_lock_interface
166 public static function get_cachelock_for_store(cache_store $store) {
167 $instance = cache_config::instance();
168 $lockconf = $instance->get_lock_for_store($store->my_name());
169 $factory = cache_factory::instance();
170 return $factory->create_lock_instance($lockconf);
174 * Returns an array of plugins without using core methods.
176 * This function explicitly does NOT use core functions as it will in some circumstances be called before Moodle has
177 * finished initialising. This happens when loading configuration for instance.
179 * @return string
181 public static function early_get_cache_plugins() {
182 global $CFG;
183 $result = array();
184 $ignored = array('CVS', '_vti_cnf', 'simpletest', 'db', 'yui', 'tests');
185 $fulldir = $CFG->dirroot.'/cache/stores';
186 $items = new DirectoryIterator($fulldir);
187 foreach ($items as $item) {
188 if ($item->isDot() or !$item->isDir()) {
189 continue;
191 $pluginname = $item->getFilename();
192 if (in_array($pluginname, $ignored)) {
193 continue;
195 if (!is_valid_plugin_name($pluginname)) {
196 // Better ignore plugins with problematic names here.
197 continue;
199 $result[$pluginname] = $fulldir.'/'.$pluginname;
200 unset($item);
202 unset($items);
203 return $result;
207 * Invalidates a given set of keys from a given definition.
209 * @todo Invalidating by definition should also add to the event cache so that sessions can be invalidated (when required).
211 * @param string $component
212 * @param string $area
213 * @param array $identifiers
214 * @param array $keys
215 * @return boolean
217 public static function invalidate_by_definition($component, $area, array $identifiers = array(), $keys = array()) {
218 $cache = cache::make($component, $area, $identifiers);
219 if (is_array($keys)) {
220 $cache->delete_many($keys);
221 } else if (is_scalar($keys)) {
222 $cache->delete($keys);
223 } else {
224 throw new coding_exception('cache_helper::invalidate_by_definition only accepts $keys as array, or scalar.');
226 return true;
230 * Invalidates a given set of keys by means of an event.
232 * Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
233 * are only supported on caches without identifiers.
235 * @param string $event
236 * @param array $keys
238 public static function invalidate_by_event($event, array $keys) {
239 $instance = cache_config::instance();
240 $invalidationeventset = false;
241 $factory = cache_factory::instance();
242 $inuse = $factory->get_caches_in_use();
243 $purgetoken = null;
244 foreach ($instance->get_definitions() as $name => $definitionarr) {
245 $definition = cache_definition::load($name, $definitionarr);
246 if ($definition->invalidates_on_event($event)) {
247 // First up check if there is a cache loader for this definition already.
248 // If there is we need to invalidate the keys from there.
249 $definitionkey = $definition->get_component().'/'.$definition->get_area();
250 if (isset($inuse[$definitionkey])) {
251 $inuse[$definitionkey]->delete_many($keys);
254 // We should only log events for application and session caches.
255 // Request caches shouldn't have events as all data is lost at the end of the request.
256 // Events should only be logged once of course and likely several definitions are watching so we
257 // track its logging with $invalidationeventset.
258 $logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
260 if ($logevent) {
261 // Get the event invalidation cache.
262 $cache = cache::make('core', 'eventinvalidation');
263 // Get any existing invalidated keys for this cache.
264 $data = $cache->get($event);
265 if ($data === false) {
266 // There are none.
267 $data = array();
269 // Add our keys to them with the current cache timestamp.
270 if (null === $purgetoken) {
271 $purgetoken = cache::get_purge_token(true);
273 foreach ($keys as $key) {
274 $data[$key] = $purgetoken;
276 // Set that data back to the cache.
277 $cache->set($event, $data);
278 // This only needs to occur once.
279 $invalidationeventset = true;
286 * Purges the cache for a specific definition.
288 * @param string $component
289 * @param string $area
290 * @param array $identifiers
291 * @return bool
293 public static function purge_by_definition($component, $area, array $identifiers = array()) {
294 // Create the cache.
295 $cache = cache::make($component, $area, $identifiers);
296 // Initialise, in case of a store.
297 if ($cache instanceof cache_store) {
298 $factory = cache_factory::instance();
299 $definition = $factory->create_definition($component, $area, null);
300 $cacheddefinition = clone $definition;
301 $cacheddefinition->set_identifiers($identifiers);
302 $cache->initialise($cacheddefinition);
304 // Purge baby, purge.
305 $cache->purge();
306 return true;
310 * Purges a cache of all information on a given event.
312 * Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
313 * are only supported on caches without identifiers.
315 * @param string $event
317 public static function purge_by_event($event) {
318 $instance = cache_config::instance();
319 $invalidationeventset = false;
320 $factory = cache_factory::instance();
321 $inuse = $factory->get_caches_in_use();
322 $purgetoken = null;
323 foreach ($instance->get_definitions() as $name => $definitionarr) {
324 $definition = cache_definition::load($name, $definitionarr);
325 if ($definition->invalidates_on_event($event)) {
326 // First up check if there is a cache loader for this definition already.
327 // If there is we need to invalidate the keys from there.
328 $definitionkey = $definition->get_component().'/'.$definition->get_area();
329 if (isset($inuse[$definitionkey])) {
330 $inuse[$definitionkey]->purge();
331 } else {
332 cache::make($definition->get_component(), $definition->get_area())->purge();
335 // We should only log events for application and session caches.
336 // Request caches shouldn't have events as all data is lost at the end of the request.
337 // Events should only be logged once of course and likely several definitions are watching so we
338 // track its logging with $invalidationeventset.
339 $logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
341 // We need to flag the event in the "Event invalidation" cache if it hasn't already happened.
342 if ($logevent && $invalidationeventset === false) {
343 // Get the event invalidation cache.
344 $cache = cache::make('core', 'eventinvalidation');
345 // Create a key to invalidate all.
346 if (null === $purgetoken) {
347 $purgetoken = cache::get_purge_token(true);
349 $data = array(
350 'purged' => $purgetoken,
352 // Set that data back to the cache.
353 $cache->set($event, $data);
354 // This only needs to occur once.
355 $invalidationeventset = true;
362 * Ensure that the stats array is ready to collect information for the given store and definition.
363 * @param string $store
364 * @param string $definition A string that identifies the definition.
365 * @param int $mode One of cache_store::MODE_*. Since 2.9.
367 protected static function ensure_ready_for_stats($store, $definition, $mode = cache_store::MODE_APPLICATION) {
368 // This function is performance-sensitive, so exit as quickly as possible
369 // if we do not need to do anything.
370 if (isset(self::$stats[$definition]['stores'][$store])) {
371 return;
373 if (!array_key_exists($definition, self::$stats)) {
374 self::$stats[$definition] = array(
375 'mode' => $mode,
376 'stores' => array(
377 $store => array(
378 'hits' => 0,
379 'misses' => 0,
380 'sets' => 0,
384 } else if (!array_key_exists($store, self::$stats[$definition]['stores'])) {
385 self::$stats[$definition]['stores'][$store] = array(
386 'hits' => 0,
387 'misses' => 0,
388 'sets' => 0,
394 * Returns a string to describe the definition.
396 * This method supports the definition as a string due to legacy requirements.
397 * It is backwards compatible when a string is passed but is not accurate.
399 * @since 2.9
400 * @param cache_definition|string $definition
401 * @return string
403 protected static function get_definition_stat_id_and_mode($definition) {
404 if (!($definition instanceof cache_definition)) {
405 // All core calls to this method have been updated, this is the legacy state.
406 // We'll use application as the default as that is the most common, really this is not accurate of course but
407 // at this point we can only guess and as it only affects calls to cache stat outside of core (of which there should
408 // be none) I think that is fine.
409 debugging('Please update you cache stat calls to pass the definition rather than just its ID.', DEBUG_DEVELOPER);
410 return array((string)$definition, cache_store::MODE_APPLICATION);
412 return array($definition->get_id(), $definition->get_mode());
416 * Record a cache hit in the stats for the given store and definition.
418 * In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a
419 * cache_definition instance. It is preferable to pass a cache definition instance.
421 * @internal
422 * @param cache_definition $store
423 * @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the
424 * actual cache_definition object now.
425 * @param int $hits The number of hits to record (by default 1)
427 public static function record_cache_hit($store, $definition, $hits = 1) {
428 list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition);
429 self::ensure_ready_for_stats($store, $definitionstr, $mode);
430 self::$stats[$definitionstr]['stores'][$store]['hits'] += $hits;
434 * Record a cache miss in the stats for the given store and definition.
436 * In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a
437 * cache_definition instance. It is preferable to pass a cache definition instance.
439 * @internal
440 * @param string $store
441 * @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the
442 * actual cache_definition object now.
443 * @param int $misses The number of misses to record (by default 1)
445 public static function record_cache_miss($store, $definition, $misses = 1) {
446 list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition);
447 self::ensure_ready_for_stats($store, $definitionstr, $mode);
448 self::$stats[$definitionstr]['stores'][$store]['misses'] += $misses;
452 * Record a cache set in the stats for the given store and definition.
454 * In Moodle 2.9 the $definition argument changed from accepting only a string to accepting a string or a
455 * cache_definition instance. It is preferable to pass a cache definition instance.
457 * @internal
458 * @param string $store
459 * @param cache_definition $definition You used to be able to pass a string here, however that is deprecated please pass the
460 * actual cache_definition object now.
461 * @param int $sets The number of sets to record (by default 1)
463 public static function record_cache_set($store, $definition, $sets = 1) {
464 list($definitionstr, $mode) = self::get_definition_stat_id_and_mode($definition);
465 self::ensure_ready_for_stats($store, $definitionstr, $mode);
466 self::$stats[$definitionstr]['stores'][$store]['sets'] += $sets;
470 * Return the stats collected so far.
471 * @return array
473 public static function get_stats() {
474 return self::$stats;
478 * Purge all of the cache stores of all of their data.
480 * Think twice before calling this method. It will purge **ALL** caches regardless of whether they have been used recently or
481 * anything. This will involve full setup of the cache + the purge operation. On a site using caching heavily this WILL be
482 * painful.
484 * @param bool $usewriter If set to true the cache_config_writer class is used. This class is special as it avoids
485 * it is still usable when caches have been disabled.
486 * Please use this option only if you really must. It's purpose is to allow the cache to be purged when it would be
487 * otherwise impossible.
489 public static function purge_all($usewriter = false) {
490 $factory = cache_factory::instance();
491 $config = $factory->create_config_instance($usewriter);
492 foreach ($config->get_all_stores() as $store) {
493 self::purge_store($store['name'], $config);
498 * Purges a store given its name.
500 * @param string $storename
501 * @param cache_config $config
502 * @return bool
504 public static function purge_store($storename, cache_config $config = null) {
505 if ($config === null) {
506 $config = cache_config::instance();
509 $stores = $config->get_all_stores();
510 if (!array_key_exists($storename, $stores)) {
511 // The store does not exist.
512 return false;
515 $store = $stores[$storename];
516 $class = $store['class'];
519 // We check are_requirements_met although we expect is_ready is going to check as well.
520 if (!$class::are_requirements_met()) {
521 return false;
523 // Found the store: is it ready?
524 /* @var cache_store $instance */
525 $instance = new $class($store['name'], $store['configuration']);
526 if (!$instance->is_ready()) {
527 unset($instance);
528 return false;
530 foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
531 $definition = cache_definition::load($id, $definition);
532 $definitioninstance = clone($instance);
533 $definitioninstance->initialise($definition);
534 $definitioninstance->purge();
535 unset($definitioninstance);
538 return true;
542 * Purges all of the stores used by a definition.
544 * Unlike cache_helper::purge_by_definition this purges all of the data from the stores not
545 * just the data relating to the definition.
546 * This function is useful when you must purge a definition that requires setup but you don't
547 * want to set it up.
549 * @param string $component
550 * @param string $area
552 public static function purge_stores_used_by_definition($component, $area) {
553 $factory = cache_factory::instance();
554 $config = $factory->create_config_instance();
555 $definition = $factory->create_definition($component, $area);
556 $stores = $config->get_stores_for_definition($definition);
557 foreach ($stores as $store) {
558 self::purge_store($store['name']);
563 * Returns the translated name of the definition.
565 * @param cache_definition $definition
566 * @return lang_string
568 public static function get_definition_name($definition) {
569 if ($definition instanceof cache_definition) {
570 return $definition->get_name();
572 $identifier = 'cachedef_'.clean_param($definition['area'], PARAM_STRINGID);
573 $component = $definition['component'];
574 if ($component === 'core') {
575 $component = 'cache';
577 return new lang_string($identifier, $component);
581 * Hashes a descriptive key to make it shorter and still unique.
582 * @param string|int $key
583 * @param cache_definition $definition
584 * @return string
586 public static function hash_key($key, cache_definition $definition) {
587 if ($definition->uses_simple_keys()) {
588 if (debugging() && preg_match('#[^a-zA-Z0-9_]#', $key)) {
589 throw new coding_exception('Cache definition '.$definition->get_id().' requires simple keys. Invalid key provided.', $key);
591 // We put the key first so that we can be sure the start of the key changes.
592 return (string)$key . '-' . $definition->generate_single_key_prefix();
594 $key = $definition->generate_single_key_prefix() . '-' . $key;
595 return sha1($key);
599 * Finds all definitions and updates them within the cache config file.
601 * @param bool $coreonly If set to true only core definitions will be updated.
603 public static function update_definitions($coreonly = false) {
604 global $CFG;
605 // Include locallib.
606 require_once($CFG->dirroot.'/cache/locallib.php');
607 // First update definitions
608 cache_config_writer::update_definitions($coreonly);
609 // Second reset anything we have already initialised to ensure we're all up to date.
610 cache_factory::reset();
614 * Update the site identifier stored by the cache API.
616 * @param string $siteidentifier
617 * @return string The new site identifier.
619 public static function update_site_identifier($siteidentifier) {
620 global $CFG;
621 // Include locallib.
622 require_once($CFG->dirroot.'/cache/locallib.php');
623 $factory = cache_factory::instance();
624 $factory->updating_started();
625 $config = $factory->create_config_instance(true);
626 $siteidentifier = $config->update_site_identifier($siteidentifier);
627 $factory->updating_finished();
628 cache_factory::reset();
629 return $siteidentifier;
633 * Returns the site identifier.
635 * @return string
637 public static function get_site_identifier() {
638 global $CFG;
639 if (!is_null(self::$siteidentifier)) {
640 return self::$siteidentifier;
642 // If site identifier hasn't been collected yet attempt to get it from the cache config.
643 $factory = cache_factory::instance();
644 // If the factory is initialising then we don't want to try to get it from the config or we risk
645 // causing the cache to enter an infinite initialisation loop.
646 if (!$factory->is_initialising()) {
647 $config = $factory->create_config_instance();
648 self::$siteidentifier = $config->get_site_identifier();
650 if (is_null(self::$siteidentifier)) {
651 // If the site identifier is still null then config isn't aware of it yet.
652 // We'll see if the CFG is loaded, and if not we will just use unknown.
653 // It's very important here that we don't use get_config. We don't want an endless cache loop!
654 if (!empty($CFG->siteidentifier)) {
655 self::$siteidentifier = self::update_site_identifier($CFG->siteidentifier);
656 } else {
657 // It's not being recorded in MUC's config and the config data hasn't been loaded yet.
658 // Likely we are initialising.
659 return 'unknown';
662 return self::$siteidentifier;
666 * Returns the site version.
668 * @return string
670 public static function get_site_version() {
671 global $CFG;
672 return (string)$CFG->version;
676 * Runs cron routines for MUC.
678 public static function cron() {
679 self::clean_old_session_data(true);
683 * Cleans old session data from cache stores used for session based definitions.
685 * @param bool $output If set to true output will be given.
687 public static function clean_old_session_data($output = false) {
688 global $CFG;
689 if ($output) {
690 mtrace('Cleaning up stale session data from cache stores.');
692 $factory = cache_factory::instance();
693 $config = $factory->create_config_instance();
694 $definitions = $config->get_definitions();
695 $purgetime = time() - $CFG->sessiontimeout;
696 foreach ($definitions as $definitionarray) {
697 // We are only interested in session caches.
698 if (!($definitionarray['mode'] & cache_store::MODE_SESSION)) {
699 continue;
701 $definition = $factory->create_definition($definitionarray['component'], $definitionarray['area']);
702 $stores = $config->get_stores_for_definition($definition);
703 // Turn them into store instances.
704 $stores = self::initialise_cachestore_instances($stores, $definition);
705 // Initialise all of the stores used for that definition.
706 foreach ($stores as $store) {
707 // If the store doesn't support searching we can skip it.
708 if (!($store instanceof cache_is_searchable)) {
709 debugging('Cache stores used for session definitions should ideally be searchable.', DEBUG_DEVELOPER);
710 continue;
712 // Get all of the keys.
713 $keys = $store->find_by_prefix(cache_session::KEY_PREFIX);
714 $todelete = array();
715 foreach ($store->get_many($keys) as $key => $value) {
716 if (strpos($key, cache_session::KEY_PREFIX) !== 0 || !is_array($value) || !isset($value['lastaccess'])) {
717 continue;
719 if ((int)$value['lastaccess'] < $purgetime || true) {
720 $todelete[] = $key;
723 if (count($todelete)) {
724 $outcome = (int)$store->delete_many($todelete);
725 if ($output) {
726 $strdef = s($definition->get_id());
727 $strstore = s($store->my_name());
728 mtrace("- Removed {$outcome} old {$strdef} sessions from the '{$strstore}' cache store.");
736 * Returns an array of stores that would meet the requirements for every definition.
738 * These stores would be 100% suitable to map as defaults for cache modes.
740 * @return array[] An array of stores, keys are the store names.
742 public static function get_stores_suitable_for_mode_default() {
743 $factory = cache_factory::instance();
744 $config = $factory->create_config_instance();
745 $requirements = 0;
746 foreach ($config->get_definitions() as $definition) {
747 $definition = cache_definition::load($definition['component'].'/'.$definition['area'], $definition);
748 $requirements = $requirements | $definition->get_requirements_bin();
750 $stores = array();
751 foreach ($config->get_all_stores() as $name => $store) {
752 if (!empty($store['features']) && ($store['features'] & $requirements)) {
753 $stores[$name] = $store;
756 return $stores;
760 * Returns stores suitable for use with a given definition.
762 * @param cache_definition $definition
763 * @return cache_store[]
765 public static function get_stores_suitable_for_definition(cache_definition $definition) {
766 $factory = cache_factory::instance();
767 $stores = array();
768 if ($factory->is_initialising() || $factory->stores_disabled()) {
769 // No suitable stores here.
770 return $stores;
771 } else {
772 $stores = self::get_cache_stores($definition);
773 // If mappingsonly is set, having 0 stores is ok.
774 if ((count($stores) === 0) && (!$definition->is_for_mappings_only())) {
775 // No suitable stores we found for the definition. We need to come up with a sensible default.
776 // If this has happened we can be sure that the user has mapped custom stores to either the
777 // mode of the definition. The first alternative to try is the system default for the mode.
778 // e.g. the default file store instance for application definitions.
779 $config = $factory->create_config_instance();
780 foreach ($config->get_stores($definition->get_mode()) as $name => $details) {
781 if (!empty($details['default'])) {
782 $stores[] = $factory->create_store_from_config($name, $details, $definition);
783 break;
788 return $stores;
792 * Returns an array of warnings from the cache API.
794 * The warning returned here are for things like conflicting store instance configurations etc.
795 * These get shown on the admin notifications page for example.
797 * @param array|null $stores An array of stores to get warnings for, or null for all.
798 * @return string[]
800 public static function warnings(array $stores = null) {
801 global $CFG;
802 if ($stores === null) {
803 require_once($CFG->dirroot.'/cache/locallib.php');
804 $stores = cache_administration_helper::get_store_instance_summaries();
806 $warnings = array();
807 foreach ($stores as $store) {
808 if (!empty($store['warnings'])) {
809 $warnings = array_merge($warnings, $store['warnings']);
812 return $warnings;