mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-57570-master' of https://github.com/mwehr/moodle
This commit is contained in:
commit
c5bd22b1ea
1 changed files with 46 additions and 3 deletions
49
cache/stores/static/lib.php
vendored
49
cache/stores/static/lib.php
vendored
|
@ -117,12 +117,19 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $simpledata = false;
|
protected $simpledata = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of items currently being stored.
|
* The number of items currently being stored.
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $storecount = 0;
|
protected $storecount = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* igbinary extension available.
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $igbinaryfound = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the store instance.
|
* Constructs the store instance.
|
||||||
*
|
*
|
||||||
|
@ -203,6 +210,7 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
$this->store = &self::register_store_id($this->storeid);
|
$this->store = &self::register_store_id($this->storeid);
|
||||||
$maxsize = $definition->get_maxsize();
|
$maxsize = $definition->get_maxsize();
|
||||||
$this->simpledata = $definition->uses_simple_data();
|
$this->simpledata = $definition->uses_simple_data();
|
||||||
|
$this->igbinaryfound = extension_loaded('igbinary');
|
||||||
if ($maxsize !== null) {
|
if ($maxsize !== null) {
|
||||||
// Must be a positive int.
|
// Must be a positive int.
|
||||||
$this->maxsize = abs((int)$maxsize);
|
$this->maxsize = abs((int)$maxsize);
|
||||||
|
@ -219,6 +227,41 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
return (is_array($this->store));
|
return (is_array($this->store));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses igbinary serializer if igbinary extension is loaded.
|
||||||
|
* Fallback to PHP serializer.
|
||||||
|
*
|
||||||
|
* @param mixed $data
|
||||||
|
* The value to be serialized.
|
||||||
|
* @return string a string containing a byte-stream representation of
|
||||||
|
* value that can be stored anywhere.
|
||||||
|
*/
|
||||||
|
protected function serialize($data) {
|
||||||
|
if ($this->igbinaryfound) {
|
||||||
|
return igbinary_serialize($data);
|
||||||
|
} else {
|
||||||
|
return serialize($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses igbinary unserializer if igbinary extension is loaded.
|
||||||
|
* Fallback to PHP unserializer.
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* The serialized string.
|
||||||
|
* @return mixed The converted value is returned, and can be a boolean,
|
||||||
|
* integer, float, string,
|
||||||
|
* array or object.
|
||||||
|
*/
|
||||||
|
protected function unserialize($str) {
|
||||||
|
if ($this->igbinaryfound) {
|
||||||
|
return igbinary_unserialize($str);
|
||||||
|
} else {
|
||||||
|
return unserialize($str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an item from the cache store given its key.
|
* Retrieves an item from the cache store given its key.
|
||||||
*
|
*
|
||||||
|
@ -233,7 +276,7 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
$key = $key['key'];
|
$key = $key['key'];
|
||||||
if (isset($this->store[$key])) {
|
if (isset($this->store[$key])) {
|
||||||
if ($this->store[$key]['serialized']) {
|
if ($this->store[$key]['serialized']) {
|
||||||
return unserialize($this->store[$key]['data']);
|
return $this->unserialize($this->store[$key]['data']);
|
||||||
} else {
|
} else {
|
||||||
return $this->store[$key]['data'];
|
return $this->store[$key]['data'];
|
||||||
}
|
}
|
||||||
|
@ -261,7 +304,7 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
$return[$key] = false;
|
$return[$key] = false;
|
||||||
if (isset($this->store[$key])) {
|
if (isset($this->store[$key])) {
|
||||||
if ($this->store[$key]['serialized']) {
|
if ($this->store[$key]['serialized']) {
|
||||||
$return[$key] = unserialize($this->store[$key]['data']);
|
$return[$key] = $this->unserialize($this->store[$key]['data']);
|
||||||
} else {
|
} else {
|
||||||
$return[$key] = $this->store[$key]['data'];
|
$return[$key] = $this->store[$key]['data'];
|
||||||
}
|
}
|
||||||
|
@ -292,7 +335,7 @@ class cachestore_static extends static_data_store implements cache_is_key_aware,
|
||||||
$this->store[$key]['data'] = $data;
|
$this->store[$key]['data'] = $data;
|
||||||
$this->store[$key]['serialized'] = false;
|
$this->store[$key]['serialized'] = false;
|
||||||
} else {
|
} else {
|
||||||
$this->store[$key]['data'] = serialize($data);
|
$this->store[$key]['data'] = $this->serialize($data);
|
||||||
$this->store[$key]['serialized'] = true;
|
$this->store[$key]['serialized'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue