Performance: Improve changes detection, so we update index only if needed

pull/247/merge
Aleksander Machniak 9 years ago
parent 11d5e7c100
commit b1e35a685c

@ -43,6 +43,7 @@ class rcube_cache
private $packed;
private $index;
private $debug;
private $index_changed = false;
private $cache = array();
private $cache_changes = array();
private $cache_sums = array();
@ -118,7 +119,6 @@ class rcube_cache
function set($key, $data)
{
$this->cache[$key] = $data;
$this->cache_changed = true;
$this->cache_changes[$key] = true;
}
@ -167,7 +167,6 @@ class rcube_cache
// Remove all keys
if ($key === null) {
$this->cache = array();
$this->cache_changed = false;
$this->cache_changes = array();
$this->cache_sums = array();
}
@ -227,10 +226,6 @@ class rcube_cache
*/
function close()
{
if (!$this->cache_changed) {
return;
}
foreach ($this->cache as $key => $data) {
// The key has been used
if ($this->cache_changes[$key]) {
@ -244,7 +239,9 @@ class rcube_cache
}
}
$this->write_index();
if ($this->index_changed) {
$this->write_index();
}
}
@ -486,6 +483,10 @@ class rcube_cache
}
}
if ($result) {
$this->index_changed = true;
}
return $result;
}
@ -513,6 +514,10 @@ class rcube_cache
}
}
if ($result) {
$this->index_changed = true;
}
if ($index) {
if (($idx = array_search($key, $this->index)) !== false) {
unset($this->index[$idx]);

@ -42,6 +42,7 @@ class rcube_cache_shared
private $index;
private $table;
private $debug;
private $index_changed = false;
private $cache = array();
private $cache_changes = array();
private $cache_sums = array();
@ -115,7 +116,6 @@ class rcube_cache_shared
function set($key, $data)
{
$this->cache[$key] = $data;
$this->cache_changed = true;
$this->cache_changes[$key] = true;
}
@ -164,7 +164,6 @@ class rcube_cache_shared
// Remove all keys
if ($key === null) {
$this->cache = array();
$this->cache_changed = false;
$this->cache_changes = array();
$this->cache_sums = array();
}
@ -222,10 +221,6 @@ class rcube_cache_shared
*/
function close()
{
if (!$this->cache_changed) {
return;
}
foreach ($this->cache as $key => $data) {
// The key has been used
if ($this->cache_changes[$key]) {
@ -239,7 +234,9 @@ class rcube_cache_shared
}
}
$this->write_index();
if ($this->index_changed) {
$this->write_index();
}
}
@ -474,6 +471,10 @@ class rcube_cache_shared
}
}
if ($result) {
$this->index_changed = true;
}
return $result;
}
@ -501,6 +502,10 @@ class rcube_cache_shared
}
}
if ($result) {
$this->index_changed = true;
}
if ($index) {
if (($idx = array_search($key, $this->index)) !== false) {
unset($this->index[$idx]);

Loading…
Cancel
Save