Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-36407 cache: Implemented options for ad_hoc caches

  • Loading branch information...
commit 2566210c6335cc991ea9eb742202994ff6c89e6b 1 parent 8ccaa29
@samhemelryk samhemelryk authored
View
23 cache/classes/definition.php
@@ -457,20 +457,31 @@ public static function load($id, array $definition, $datasourceaggregate = null)
* @param int $mode One of cache_store::MODE_*
* @param string $component The component this definition relates to.
* @param string $area The area this definition relates to.
- * @param string $overrideclass The class to use as the loader.
- * @param bool $persistent If this cache should be persistent.
+ * @param array $options An array of options, available options are:
+ * - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
+ * - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
+ * - overrideclass : The class to use as the loader.
+ * - persistent : If set to true the cache will persist construction requests.
* @return cache_application|cache_session|cache_request
*/
- public static function load_adhoc($mode, $component, $area, $overrideclass = null, $persistent = false) {
+ public static function load_adhoc($mode, $component, $area, array $options = array()) {
$id = 'adhoc/'.$component.'_'.$area;
$definition = array(
'mode' => $mode,
'component' => $component,
'area' => $area,
- 'persistent' => $persistent
);
- if (!is_null($overrideclass)) {
- $definition['overrideclass'] = $overrideclass;
+ if (!empty($options['simplekeys'])) {
+ $definition['simplekeys'] = $options['simplekeys'];
+ }
+ if (!empty($options['simpledata'])) {
+ $definition['simpledata'] = $options['simpledata'];
+ }
+ if (!empty($options['persistent'])) {
+ $definition['persistent'] = $options['persistent'];
+ }
+ if (!empty($options['overrideclass'])) {
+ $definition['overrideclass'] = $options['overrideclass'];
}
return self::load($id, $definition, null);
}
View
9 cache/classes/factory.php
@@ -151,16 +151,19 @@ public function create_cache_from_definition($component, $area, array $identifie
* @param string $component
* @param string $area
* @param array $identifiers
- * @param bool $persistent
+ * @param array $options An array of options, available options are:
+ * - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
+ * - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
+ * - persistent : If set to true the cache will persist construction requests.
* @return cache_application|cache_session|cache_request
*/
- public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), $persistent = false) {
+ public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
$key = "{$mode}_{$component}_{$area}";
if (array_key_exists($key, $this->cachesfromparams)) {
return $this->cachesfromparams[$key];
}
// 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, null, $persistent);
+ $definition = cache_definition::load_adhoc($mode, $component, $area, $options);
$definition->set_identifiers($identifiers);
$cache = $this->create_cache($definition, $identifiers);
if ($definition->should_be_persistent()) {
View
9 cache/classes/loaders.php
@@ -176,12 +176,15 @@ public static function make($component, $area, array $identifiers = array(), $ag
* @param string $component The component this cache relates to.
* @param string $area The area this cache relates to.
* @param array $identifiers Any additional identifiers that should be provided to the definition.
- * @param bool $persistent If set to true the cache will persist construction requests.
+ * @param array $options An array of options, available options are:
+ * - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
+ * - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
+ * - persistent : If set to true the cache will persist construction requests.
* @return cache_application|cache_session|cache_store
*/
- public static function make_from_params($mode, $component, $area, array $identifiers = array(), $persistent = false) {
+ public static function make_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
$factory = cache_factory::instance();
- return $factory->create_cache_from_params($mode, $component, $area, $identifiers, $persistent);
+ return $factory->create_cache_from_params($mode, $component, $area, $identifiers, $options);
}
/**
View
6 cache/testperformance.php
@@ -47,9 +47,9 @@
$requesttable = clone($applicationtable);
-$application = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cache', 'applicationtest', null, false);
-$session = cache_definition::load_adhoc(cache_store::MODE_SESSION, 'cache', 'sessiontest', null, false);
-$request = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cache', 'requesttest', null, false);
+$application = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cache', 'applicationtest');
+$session = cache_definition::load_adhoc(cache_store::MODE_SESSION, 'cache', 'sessiontest');
+$request = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cache', 'requesttest');
$strinvalidplugin = new lang_string('invalidplugin', 'cache');
$strunsupportedmode = new lang_string('unsupportedmode', 'cache');
Please sign in to comment.
Something went wrong with that request. Please try again.