From 2e1e266c9a99f94faed219c6d6b466f8d286759d Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 5 Nov 2012 10:28:07 +1300 Subject: [PATCH] MDL-36362 cache: added simpledata definition option --- cache/README.md | 2 ++ cache/classes/definition.php | 21 +++++++++++++++++++++ cache/classes/loaders.php | 3 +++ lib/db/caches.php | 7 +++++-- version.php | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cache/README.md b/cache/README.md index f5e5816c566..40a723d5825 100644 --- a/cache/README.md +++ b/cache/README.md @@ -9,6 +9,7 @@ A definition: $definitions = array( 'string' => array( // Required, unique to the component 'mode' => cache_store::MODE_APPLICATION, // Required + 'simpledata' => false, // Optional 'requireidentifiers' => array( // Optional 'lang' ), @@ -104,6 +105,7 @@ The following settings are required for a definition: * mode - Application, session or request. The following optional settings can also be defined: +* simpledata - Set to true if you know that you will only be storing scalar values or arrays of scalar values. Avoids costly investigation of data types. * requireidentifiers - Any identifiers the definition requires. Must be provided when creating the loader. * requiredataguarantee - If set to true then only stores that support data guarantee will be used. * requiremultipleidentifiers - If set to true then only stores that support multiple identifiers will be used. diff --git a/cache/classes/definition.php b/cache/classes/definition.php index a73c947d6de..dcc219d805a 100644 --- a/cache/classes/definition.php +++ b/cache/classes/definition.php @@ -39,6 +39,8 @@ defined('MOODLE_INTERNAL') || die(); * [int] Sets the mode for the definition. Must be one of cache_store::MODE_* * * Optional settings: + * + simpledata + * [bool] If set to true we know that the data is scalar or array of scalar. * + requireidentifiers * [array] An array of identifiers that must be provided to the cache when it is created. * + requiredataguarantee @@ -127,6 +129,12 @@ class cache_definition { */ protected $area; + /** + * Set to true if we know the data is scalar or array of scalar. + * @var bool + */ + protected $simpledata = false; + /** * An array of identifiers that must be provided when the definition is used to create a cache. * @var array @@ -281,6 +289,7 @@ class cache_definition { $area = (string)$definition['area']; // Set the defaults. + $simpledata = false; $requireidentifiers = array(); $requiredataguarantee = false; $requiremultipleidentifiers = false; @@ -297,6 +306,9 @@ class cache_definition { $mappingsonly = false; $invalidationevents = array(); + if (array_key_exists('simpledata', $definition)) { + $simpledata = (bool)$definition['simpledata']; + } if (array_key_exists('requireidentifiers', $definition)) { $requireidentifiers = (array)$definition['requireidentifiers']; } @@ -398,6 +410,7 @@ class cache_definition { $cachedefinition->mode = $mode; $cachedefinition->component = $component; $cachedefinition->area = $area; + $cachedefinition->simpledata = $simpledata; $cachedefinition->requireidentifiers = $requireidentifiers; $cachedefinition->requiredataguarantee = $requiredataguarantee; $cachedefinition->requiremultipleidentifiers = $requiremultipleidentifiers; @@ -534,6 +547,14 @@ class cache_definition { return $this->mappingsonly; } + /** + * Returns true if the data is known to be scalar or array of scalar. + * @return bool + */ + public function uses_simple_data() { + return $this->simpledata; + } + /** * Returns true if this definition requires a data guarantee from the cache stores being used. * @return bool diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index aa6a0ed0b50..ef7b308d11b 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -498,6 +498,9 @@ class cache implements cache_loader { * @param stdClass|array $data */ protected function unref($data) { + if ($this->definition->uses_simple_data()) { + return $data; + } // Check if it requires serialisation in order to produce a reference free copy. if ($this->requires_serialisation($data)) { // Damn, its going to have to be serialise. diff --git a/lib/db/caches.php b/lib/db/caches.php index ce82797d12a..acf9b0eab60 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -31,6 +31,7 @@ $definitions = array( // Used to store processed lang files. 'string' => array( 'mode' => cache_store::MODE_APPLICATION, + 'simpledata' => true, 'persistent' => true, 'persistentmaxsize' => 3 ), @@ -48,14 +49,16 @@ $definitions = array( // Used to store data from the config + config_plugins table in the database. 'config' => array( 'mode' => cache_store::MODE_APPLICATION, - 'persistent' => true + 'persistent' => true, + 'simpledata' => true ), // Event invalidation cache. 'eventinvalidation' => array( 'mode' => cache_store::MODE_APPLICATION, 'persistent' => true, - 'requiredataguarantee' => true + 'requiredataguarantee' => true, + 'simpledata' => true, ), // Cache for question definitions. This is used by the question_bank class. diff --git a/version.php b/version.php index 4904073e6d7..54e033a6846 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012110101.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012110102.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes