summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-09 20:02:52 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-09 20:02:52 +0200
commit9e674f74ec4f36f11f30e2f84a48ef6cea33a9d9 (patch)
tree959c905339cba34d0ba73f7c4b1bf4033a5d6f01 /system/libraries/Cache
parentba9350fcb2e6eb20234fd2cb8e4d081549bef472 (diff)
Cleanup the new Redis cache driver and add a changelog entry for it
Diffstat (limited to 'system/libraries/Cache')
-rw-r--r--system/libraries/Cache/Cache.php2
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php109
2 files changed, 63 insertions, 48 deletions
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index 8d8c0db34..4395cf411 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.php
@@ -226,4 +226,4 @@ class CI_Cache extends CI_Driver_Library {
}
/* End of file Cache.php */
-/* Location: ./system/libraries/Cache/Cache.php */
+/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index 205f17cd1..e4a26b5f0 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -21,12 +21,10 @@
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 2.0
+ * @since Version 3.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Redis Caching Class
*
@@ -38,12 +36,11 @@
*/
class CI_Cache_redis extends CI_Driver
{
-
/**
* Default config
*
* @static
- * @var array
+ * @var array
*/
protected static $_default_config = array(
'host' => '127.0.0.1',
@@ -55,43 +52,32 @@ class CI_Cache_redis extends CI_Driver
/**
* Redis connection
*
- * @var Redis
+ * @var Redis
*/
protected $_redis;
- /**
- * Class destructor
- *
- * Closes the connection to Redis if present.
- *
- * @return void
- */
- public function __destruct()
- {
- if ($this->_redis)
- {
- $this->_redis->close();
- }
- }
+ // ------------------------------------------------------------------------
/**
* Get cache
*
- * @param string $key Cache key identifier
- * @return mixed
+ * @param string Cache key identifier
+ * @return mixed
*/
public function get($key)
{
return $this->_redis->get($key);
}
+ // ------------------------------------------------------------------------
+
/**
* Save cache
*
- * @param string $key Cache key identifier
- * @param mixed $value Data to save
- * @param integer $ttl Time to live
- * @return boolean
+ * @param string Cache key identifier
+ * @param mixed Data to save
+ * @param int Time to live
+ * @return bool
*/
public function save($key, $value, $ttl = NULL)
{
@@ -100,90 +86,102 @@ class CI_Cache_redis extends CI_Driver
: $this->_redis->set($key, $value);
}
+ // ------------------------------------------------------------------------
+
/**
* Delete from cache
*
- * @param string $key Cache key
- * @return boolean
+ * @param string Cache key
+ * @return bool
*/
public function delete($key)
{
return ($this->_redis->delete($key) === 1);
}
+ // ------------------------------------------------------------------------
+
/**
* Clean cache
*
- * @return boolean
- * @see Redis::flushDB()
+ * @return bool
+ * @see Redis::flushDB()
*/
public function clean()
{
return $this->_redis->flushDB();
}
+ // ------------------------------------------------------------------------
+
/**
* Get cache driver info
*
- * @param string $type Not supported in Redis. Only included in order to offer a
- * consistent cache API.
- * @return array
- * @see Redis::info()
+ * @param string Not supported in Redis.
+ * Only included in order to offer a
+ * consistent cache API.
+ * @return array
+ * @see Redis::info()
*/
public function cache_info($type = NULL)
{
return $this->_redis->info();
}
+ // ------------------------------------------------------------------------
+
/**
* Get cache metadata
*
- * @param string $key Cache key
- * @return array
+ * @param string Cache key
+ * @return array
*/
public function get_metadata($key)
{
$value = $this->get($key);
if ($value)
- {
+ {
return array(
'expire' => time() + $this->_redis->ttl($key),
'data' => $value
);
}
+
+ return FALSE;
}
+ // ------------------------------------------------------------------------
+
/**
* Check if Redis driver is supported
*
- * @return boolean
+ * @return bool
*/
public function is_supported()
{
if (extension_loaded('redis'))
- {
+ {
$this->_setup_redis();
-
return TRUE;
}
else
{
log_message('error', 'The Redis extension must be loaded to use Redis cache.');
-
return FALSE;
}
-
}
+ // ------------------------------------------------------------------------
+
/**
* Setup Redis config and connection
*
- * Loads Redis config file if present. Will halt execution if a Redis connection
- * can't be established.
+ * Loads Redis config file if present. Will halt execution
+ * if a Redis connection can't be established.
*
- * @return void
- * @see Redis::connect()
+ * @return bool
+ * @see Redis::connect()
*/
protected function _setup_redis()
{
@@ -214,8 +212,25 @@ class CI_Cache_redis extends CI_Driver
}
}
+ // ------------------------------------------------------------------------
+
+ /**
+
+ * Class destructor
+ *
+ * Closes the connection to Redis if present.
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->_redis)
+ {
+ $this->_redis->close();
+ }
+ }
+
}
-// End Class
/* End of file Cache_redis.php */
/* Location: ./system/libraries/Cache/drivers/Cache_redis.php */ \ No newline at end of file