summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-08-18 15:20:05 +0200
committerAndrey Andreev <narf@devilix.net>2014-08-18 15:20:05 +0200
commit2492b500c1b0f20569b34a0848e977f8a722a86b (patch)
tree849ed99eff4c4c479048ecac5f89a2a46e1a51cd /system/libraries/Cache
parent5e9b936390f0b72ee899985bd21204b50a7c917e (diff)
Optimize Redis serialized values support
Rel: PR #3186
Diffstat (limited to 'system/libraries/Cache')
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php36
1 files changed, 19 insertions, 17 deletions
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index b8f3f5d9a..ab4fd0da9 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -63,7 +63,7 @@ class CI_Cache_redis extends CI_Driver
*
* @var array
*/
- protected $_serialized;
+ protected $_serialized = array();
// ------------------------------------------------------------------------
@@ -77,7 +77,7 @@ class CI_Cache_redis extends CI_Driver
{
$value = $this->_redis->get($key);
- if ($value !== FALSE && in_array($key, $this->_serialized, TRUE))
+ if ($value !== FALSE && isset($this->_serialized[$key]))
{
return unserialize($value);
}
@@ -100,18 +100,17 @@ class CI_Cache_redis extends CI_Driver
{
if (is_array($data) OR is_object($data))
{
- $data = serialize($data);
-
- if ( ! in_array($id, $this->_serialized, TRUE))
+ if ( ! $this->_redis->sAdd('_ci_redis_serialized', $id))
{
- $this->_serialized[] = $id;
+ return FALSE;
}
- $this->_redis->sAdd('_ci_redis_serialized', $id);
+ isset($this->_serialized[$id]) OR $this->_serialized[$id] = TRUE;
+ $data = serialize($data);
}
- elseif (($index_key = array_search($id, $this->_serialized, TRUE)) !== FALSE)
+ elseif (isset($this->_serialized[$id]))
{
- unset($this->_serialized[$index_key]);
+ $this->_serialized[$id] = NULL;
$this->_redis->sRemove('_ci_redis_serialized', $id);
}
@@ -130,13 +129,18 @@ class CI_Cache_redis extends CI_Driver
*/
public function delete($key)
{
- if ($this->_redis->delete($key) === 1 && in_array($key, $this->_serialized, TRUE))
+ if ($this->_redis->delete($key) !== 1)
{
+ return FALSE;
+ }
+
+ if (isset($this->_serialized[$key]))
+ {
+ $this->_serialized[$key] = NULL;
$this->_redis->sRemove('_ci_redis_serialized', $key);
- return TRUE;
}
- return FALSE;
+ return TRUE;
}
// ------------------------------------------------------------------------
@@ -293,12 +297,10 @@ class CI_Cache_redis extends CI_Driver
}
// Initialize the index of serialized values.
- $this->_serialized = $this->_redis->sMembers('_ci_redis_serialized');
-
- if (empty($this->_serialized))
+ $serialized = $this->_redis->sMembers('_ci_redis_serialized');
+ if ( ! empty($serialized))
{
- // On error FALSE is returned, ensure array type for empty index.
- $this->_serialized = array();
+ $this->_serialized = array_flip($this->_serialized);
}
return TRUE;