mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-36362 cache: added simpledata definition option
This commit is contained in:
parent
6109f2112c
commit
2e1e266c9a
2
cache/README.md
vendored
2
cache/README.md
vendored
@ -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.
|
||||
|
21
cache/classes/definition.php
vendored
21
cache/classes/definition.php
vendored
@ -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
|
||||
|
3
cache/classes/loaders.php
vendored
3
cache/classes/loaders.php
vendored
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user