[CORE] Fixed small anti-pattern on cache code. Plugins had to throw EndCache events, when this should be done by the library

This commit is contained in:
Miguel Dantas 2019-08-13 01:32:54 +01:00 committed by Diogo Peralta Cordeiro
parent 19d68c9f8e
commit 4f8ede8239

View File

@ -118,7 +118,6 @@ class Cache
*
* @return string full key
*/
static function codeKey($extra)
{
static $prefix = null;
@ -175,12 +174,12 @@ class Cache
$value = false;
common_perf_counter('Cache::get', $key);
if (Event::handle('StartCacheGet', array(&$key, &$value))) {
if (Event::handle('StartCacheGet', [&$key, &$value])) {
if ($this->_inlineCache && array_key_exists($key, $this->_items)) {
$value = unserialize($this->_items[$key]);
}
Event::handle('EndCacheGet', array($key, &$value));
}
Event::handle('EndCacheGet', [$key, &$value]);
return $value;
}
@ -200,18 +199,13 @@ class Cache
$success = false;
common_perf_counter('Cache::set', $key);
if (Event::handle('StartCacheSet', array(&$key, &$value, &$flag,
&$expiry, &$success))) {
if (Event::handle('StartCacheSet', [&$key, &$value, &$flag, &$expiry, &$success])) {
if ($this->_inlineCache) {
$this->_items[$key] = serialize($value);
}
$success = true;
Event::handle('EndCacheSet', array($key, $value, $flag,
$expiry));
}
Event::handle('EndCacheSet', [$key, $value, $flag, $expiry]);
return $success;
}
@ -229,7 +223,7 @@ class Cache
{
$value = false;
common_perf_counter('Cache::increment', $key);
if (Event::handle('StartCacheIncrement', array(&$key, &$step, &$value))) {
if (Event::handle('StartCacheIncrement', [&$key, &$step, &$value])) {
// Fallback is not guaranteed to be atomic,
// and may original expiry value.
$value = $this->get($key);
@ -238,8 +232,8 @@ class Cache
$ok = $this->set($key, $value);
$got = $this->get($key);
}
Event::handle('EndCacheIncrement', array($key, $step, $value));
}
Event::handle('EndCacheIncrement', [$key, $step, $value]);
return $value;
}
@ -255,13 +249,13 @@ class Cache
$success = false;
common_perf_counter('Cache::delete', $key);
if (Event::handle('StartCacheDelete', array(&$key, &$success))) {
if (Event::handle('StartCacheDelete', [&$key, &$success])) {
if ($this->_inlineCache && array_key_exists($key, $this->_items)) {
unset($this->_items[$key]);
}
$success = true;
Event::handle('EndCacheDelete', array($key));
}
Event::handle('EndCacheDelete', [$key]);
return $success;
}
@ -276,10 +270,10 @@ class Cache
{
$success = false;
if (Event::handle('StartCacheReconnect', array(&$success))) {
if (Event::handle('StartCacheReconnect', [&$success])) {
$success = true;
Event::handle('EndCacheReconnect', array());
}
Event::handle('EndCacheReconnect', []);
return $success;
}