*/
protected $definitionhash = null;
- /**
- * An identifier to make cache keys predictably unique.
- * @var string
- */
- protected $cacheidentifier = '0';
-
/**
* Creates a cache definition given a definition from the cache configuration or from a caches.php file.
*
$this->keyprefixmulti = null;
}
- /**
- * Sets an identifier for the cache.
- * This can be used
- * @param string $identifier
- */
- public function set_cache_identifier($identifier) {
- $this->cacheidentifier = (string)$identifier;
- }
-
/**
* Returns the requirements of this definition as a binary flag.
* @return int
public function generate_single_key_prefix() {
if ($this->keyprefixsingle === null) {
$this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area;
- $this->keyprefixsingle .= '/'.$this->cacheidentifier;
+ $this->keyprefixsingle .= '/'.$this->get_cache_identifier();
$identifiers = $this->get_identifiers();
if ($identifiers) {
foreach ($identifiers as $key => $value) {
'mode' => $this->mode,
'component' => $this->component,
'area' => $this->area,
- 'siteidentifier' => $this->cacheidentifier
+ 'siteidentifier' => $this->get_cache_identifier()
);
if (!empty($this->identifiers)) {
$identifiers = array();
public function get_invalidation_events() {
return $this->invalidationevents;
}
+
+ /**
+ * Returns a cache identification string.
+ *
+ * @return string A string to be used as part of keys.
+ */
+ protected function get_cache_identifier() {
+ return cache_helper::get_site_identifier();
+ }
}
\ No newline at end of file
// Get the class. Note this is a late static binding so we need to use get_called_class.
$definition = cache_definition::load_adhoc($mode, $component, $area, $options);
$config = $this->create_config_instance();
- $definition->set_cache_identifier($config->get_site_identifier());
$definition->set_identifiers($identifiers);
$cache = $this->create_cache($definition, $identifiers);
if ($definition->should_be_persistent()) {
} else {
$definition = cache_definition::load($id, $definition, $aggregate);
}
- $definition->set_cache_identifier($instance->get_site_identifier());
}
$this->definitions[$id] = $definition;
}
*/
protected static $instance;
+ /**
+ * The site identifier used by the cache.
+ * Set the first time get_site_identifier is called.
+ * @var string
+ */
+ protected static $siteidentifier = null;
+
/**
* Returns true if the cache API can be initialised before Moodle has finished initialising itself.
*
$factory = cache_factory::instance();
foreach ($instance->get_definitions() as $name => $definitionarr) {
$definition = cache_definition::load($name, $definitionarr);
- $definition->set_cache_identifier($instance->get_site_identifier());
if ($definition->invalidates_on_event($event)) {
// OK at this point we know that the definition has information to invalidate on the event.
// There are two routes, either its an application cache in which case we can invalidate it now.
$factory = cache_factory::instance();
foreach ($instance->get_definitions() as $name => $definitionarr) {
$definition = cache_definition::load($name, $definitionarr);
- $definition->set_cache_identifier($instance->get_site_identifier());
if ($definition->invalidates_on_event($event)) {
// Create the cache.
$cache = $factory->create_cache($definition);
$factory->updating_finished();
cache_factory::reset();
}
+
+ /**
+ * Returns the site identifier.
+ *
+ * @return string
+ */
+ public static function get_site_identifier() {
+ if (is_null(self::$siteidentifier)) {
+ $factory = cache_factory::instance();
+ $config = $factory->create_config_instance();
+ self::$siteidentifier = $config->get_site_identifier();
+ }
+ return self::$siteidentifier;
+ }
+
+ /**
+ * Returns the site version.
+ *
+ * @return string
+ */
+ public static function get_site_version() {
+ global $CFG;
+ return (string)$CFG->version;
+ }
}
\ No newline at end of file