From 1e8be299b1c0f6385fb0536a6983147bd8ac029e Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Sat, 21 Jan 2012 12:25:08 +0100 Subject: Added redis cache driver. --- system/libraries/Cache/Cache.php | 2 +- system/libraries/Cache/drivers/Cache_redis.php | 217 +++++++++++++++++++++++++ 2 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 system/libraries/Cache/drivers/Cache_redis.php (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 2e78a6660..25555506c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -39,7 +39,7 @@ class CI_Cache extends CI_Driver_Library { protected $valid_drivers = array( - 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy' + 'cache_apc', 'cache_file', 'cache_memcached', 'cache_redis', 'cache_dummy' ); protected $_cache_path = NULL; // Path of cache files (if file-based cache) diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php new file mode 100644 index 000000000..9eb7a8d4e --- /dev/null +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -0,0 +1,217 @@ + + * @link + */ +class CI_Cache_redis extends CI_Driver +{ + + /** + * Default config + * + * @access private + * @static + * @var array + */ + private static $_default_config = array( + 'host' => '127.0.0.1', + 'port' => 6379, + 'timeout' => 0 + ); + + /** + * Redis connection + * + * @access private + * @var Redis + */ + private $_redis; + + /** + * Class destructor + * + * Closes the connection to Redis if present. + * + * @access public + * @return void + */ + public function __destruct() + { + if ($this->_redis) + { + $this->_redis->close(); + } + } + + /** + * Get cache + * + * @access public + * @param string $key Cache key identifier + * @return mixed + */ + public function get($key) + { + return $this->_redis->get($key); + } + + /** + * Save cache + * + * @access public + * @param string $key Cache key identifier + * @param mixed $value Data to save + * @param integer $ttl Time to live + * @return boolean + */ + public function save($key, $value, $ttl = NULL) + { + return ($ttl) + ? $this->_redis->setex($key, $ttl, $value) + : $this->_redis->set($key, $value); + } + + /** + * Delete from cache + * + * @access public + * @param string $key Cache key + * @return boolean + */ + public function delete($key) + { + return ($this->_redis->delete($key) === 1); + } + + /** + * Clean cache + * + * @access public + * @return boolean + * @see Redis::flushDB() + */ + public function clean() + { + return $this->_redis->flushDB(); + } + + /** + * Get cache driver info + * + * @access public + * @param string $type 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 + * + * @access public + * @param string $key 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 + ); + } + } + + /** + * Check if Redis driver is supported + * + * @access public + * @return boolean + */ + 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. + * + * @access private + * @return void + * @see Redis::connect() + */ + private function _setup_redis() + { + $config = array(); + $CI =& get_instance(); + + if ($CI->config->load('redis', TRUE, TRUE)) + { + $config += $CI->config->item('redis'); + } + + $config = array_merge(self::$_default_config, $config); + + $this->_redis = new Redis(); + + try + { + $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } + catch (RedisException $e) + { + show_error('Redis connection refused. ' . $e->getMessage()); + } + } + +} +// End Class + +/* End of file Cache_redis.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_redis.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3573af8b98ceeb2308a1eaf02ee3b327dfca82b0 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Sat, 21 Jan 2012 20:33:12 +0100 Subject: Fixed syntax according to feedback. --- system/libraries/Cache/drivers/Cache_redis.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 9eb7a8d4e..f3acc6e46 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -30,11 +30,10 @@ class CI_Cache_redis extends CI_Driver /** * Default config * - * @access private * @static * @var array */ - private static $_default_config = array( + protected static $_default_config = array( 'host' => '127.0.0.1', 'port' => 6379, 'timeout' => 0 @@ -43,17 +42,15 @@ class CI_Cache_redis extends CI_Driver /** * Redis connection * - * @access private * @var Redis */ - private $_redis; + protected $_redis; /** * Class destructor * * Closes the connection to Redis if present. * - * @access public * @return void */ public function __destruct() @@ -67,7 +64,6 @@ class CI_Cache_redis extends CI_Driver /** * Get cache * - * @access public * @param string $key Cache key identifier * @return mixed */ @@ -79,7 +75,6 @@ class CI_Cache_redis extends CI_Driver /** * Save cache * - * @access public * @param string $key Cache key identifier * @param mixed $value Data to save * @param integer $ttl Time to live @@ -95,7 +90,6 @@ class CI_Cache_redis extends CI_Driver /** * Delete from cache * - * @access public * @param string $key Cache key * @return boolean */ @@ -107,7 +101,6 @@ class CI_Cache_redis extends CI_Driver /** * Clean cache * - * @access public * @return boolean * @see Redis::flushDB() */ @@ -119,7 +112,6 @@ class CI_Cache_redis extends CI_Driver /** * Get cache driver info * - * @access public * @param string $type Not supported in Redis. Only included in order to offer a * consistent cache API. * @return array @@ -133,7 +125,6 @@ class CI_Cache_redis extends CI_Driver /** * Get cache metadata * - * @access public * @param string $key Cache key * @return array */ @@ -153,7 +144,6 @@ class CI_Cache_redis extends CI_Driver /** * Check if Redis driver is supported * - * @access public * @return boolean */ public function is_supported() @@ -166,10 +156,7 @@ class CI_Cache_redis extends CI_Driver } else { - log_message( - 'error', - 'The Redis extension must be loaded to use Redis cache.' - ); + log_message('error', 'The Redis extension must be loaded to use Redis cache.'); return FALSE; } @@ -182,7 +169,6 @@ class CI_Cache_redis extends CI_Driver * Loads Redis config file if present. Will halt execution if a Redis connection * can't be established. * - * @access private * @return void * @see Redis::connect() */ -- cgit v1.2.3-24-g4f1b From 5a1d953e8a492326b8e8cbd0473b1593fe42cfa6 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Mon, 23 Jan 2012 23:20:26 +0100 Subject: Updated redis driver doc block. --- system/libraries/Cache/drivers/Cache_redis.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index f3acc6e46..5d42905cb 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -4,12 +4,24 @@ * * An open source application development framework for PHP 5.1.6 or newer * - * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html - * @link http://codeigniter.com - * @since Version 2.0 + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @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 * @filesource */ -- cgit v1.2.3-24-g4f1b From 0b48dd40db6a9ddb1382c9e6a1eededf76182dfb Mon Sep 17 00:00:00 2001 From: Burak Erdem Date: Mon, 6 Feb 2012 17:28:33 +0200 Subject: Filesystem cache metadata function return correct TTL now. --- system/libraries/Cache/drivers/Cache_file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 4a81b0422..ff8895724 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -167,13 +167,13 @@ class CI_Cache_file extends CI_Driver { { $mtime = filemtime($this->_cache_path.$id); - if ( ! isset($data['data']['ttl'])) + if ( ! isset($data['ttl'])) { return FALSE; } return array( - 'expire' => $mtime + $data['data']['ttl'], + 'expire' => $mtime + $data['ttl'], 'mtime' => $mtime ); } -- cgit v1.2.3-24-g4f1b From 210e664abe857ddd267a7ba8713e2318d3e59a9c Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Mon, 23 Apr 2012 10:13:46 +0200 Subject: Added redis auth support. --- system/libraries/Cache/drivers/Cache_redis.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 5d42905cb..8c650ff43 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -47,6 +47,7 @@ class CI_Cache_redis extends CI_Driver */ protected static $_default_config = array( 'host' => '127.0.0.1', + 'password' => null, 'port' => 6379, 'timeout' => 0 ); @@ -206,6 +207,10 @@ class CI_Cache_redis extends CI_Driver { show_error('Redis connection refused. ' . $e->getMessage()); } + + if (isset($config['password'])) { + $this->_redis->auth($config['password']); + } } } -- cgit v1.2.3-24-g4f1b From 3093042b0f5eafac61a49662ab52e06313eca810 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 25 Apr 2012 12:32:58 +0200 Subject: Align and sort valid cache drivers. --- system/libraries/Cache/Cache.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 16d83432b..82657ce58 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -37,13 +37,13 @@ class CI_Cache extends CI_Driver_Library { protected $valid_drivers = array( - 'cache_apc', - 'cache_file', - 'cache_memcached', - 'cache_dummy', - 'cache_wincache', - 'cache_redis' - ); + 'cache_apc', + 'cache_dummy' + 'cache_file', + 'cache_memcached' + 'cache_redis', + 'cache_wincache' + ); protected $_cache_path = NULL; // Path of cache files (if file-based cache) protected $_adapter = 'dummy'; -- cgit v1.2.3-24-g4f1b From 6581cac4d2b5fef69478ce1a5c3464200bfcbba5 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Wed, 25 Apr 2012 12:35:41 +0200 Subject: Added missing commas. --- system/libraries/Cache/Cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 82657ce58..5c9d78735 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -38,9 +38,9 @@ class CI_Cache extends CI_Driver_Library { protected $valid_drivers = array( 'cache_apc', - 'cache_dummy' + 'cache_dummy', 'cache_file', - 'cache_memcached' + 'cache_memcached', 'cache_redis', 'cache_wincache' ); -- cgit v1.2.3-24-g4f1b From bf50a3b15c70441a72ec3012319cd63425ba4d20 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Sun, 27 May 2012 19:04:43 -0500 Subject: Fix issue where cache backup is ignored on first call. --- system/libraries/Cache/Cache.php | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index ba732ee8e..53f9f81a7 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -68,7 +68,7 @@ class CI_Cache extends CI_Driver_Library { * * @param string */ - protected $_backup_driver; + protected $_backup_driver = 'dummy'; /** * Constructor @@ -102,6 +102,22 @@ class CI_Cache extends CI_Driver_Library { $this->_backup_driver = $config['backup']; } } + + // If the specified adapter isn't available, check the backup. + if ( ! $this->is_supported($this->_adapter)) + { + if ( ! $this->is_supported($this->_backup_driver)) + { + // Backup isn't supported either. Default to 'Dummy' driver. + log_message('error', 'Cache adapter "'.$this->_adapter.'" and backup "'.$this->_backup_driver.'" are both unavailable. Cache is now using "Dummy" adapter.'); + $this->_adapter = 'dummy'; + } + else + { + // Backup is supported. Set it to primary. + $this->_adapter = $this->_backup_driver; + } + } } // ------------------------------------------------------------------------ @@ -206,26 +222,6 @@ class CI_Cache extends CI_Driver_Library { return $support[$driver]; } - // ------------------------------------------------------------------------ - - /** - * __get() - * - * @param child - * @return object - */ - public function __get($child) - { - $obj = parent::__get($child); - - if ( ! $this->is_supported($child)) - { - $this->_adapter = $this->_backup_driver; - } - - return $obj; - } - } /* End of file Cache.php */ -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Cache/drivers/Cache_file.php | 2 +- system/libraries/Cache/drivers/Cache_memcached.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index f0eb8bdf7..ce2c2b13a 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -53,7 +53,7 @@ class CI_Cache_file extends CI_Driver { $CI =& get_instance(); $CI->load->helper('file'); $path = $CI->config->item('cache_path'); - $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; + $this->_cache_path = ($path === '') ? APPPATH.'cache/' : $path; } // ------------------------------------------------------------------------ diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 1df149c2d..bf90f6197 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -212,7 +212,7 @@ class CI_Cache_memcached extends CI_Driver { $cache_server['weight'] = $this->_memcache_conf['default']['default_weight']; } - if (get_class($this->_memcached) == 'Memcache') + if (get_class($this->_memcached) === 'Memcache') { // Third parameter is persistance and defaults to TRUE. $this->_memcached->addServer( -- cgit v1.2.3-24-g4f1b From 0f0b76980cb07f39b20c8591882aeae3854f016c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 7 Jun 2012 14:57:04 +0300 Subject: Deprecated do_hash() and read_file() in favor of hash() and file_get_contents() respectively --- system/libraries/Cache/drivers/Cache_file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index ce2c2b13a..5170de821 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -71,7 +71,7 @@ class CI_Cache_file extends CI_Driver { return FALSE; } - $data = unserialize(read_file($this->_cache_path.$id)); + $data = unserialize(file_get_contents($this->_cache_path.$id)); if (time() > $data['time'] + $data['ttl']) { @@ -165,7 +165,7 @@ class CI_Cache_file extends CI_Driver { return FALSE; } - $data = unserialize(read_file($this->_cache_path.$id)); + $data = unserialize(file_get_contents($this->_cache_path.$id)); if (is_array($data)) { -- cgit v1.2.3-24-g4f1b From 5ccf5ce0189669f003a578de88936209c7b331fd Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Fri, 8 Jun 2012 11:47:17 +0200 Subject: Fixed according to feedback. --- system/libraries/Cache/drivers/Cache_redis.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 8c650ff43..205f17cd1 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * @@ -47,7 +47,7 @@ class CI_Cache_redis extends CI_Driver */ protected static $_default_config = array( 'host' => '127.0.0.1', - 'password' => null, + 'password' => NULL, 'port' => 6379, 'timeout' => 0 ); @@ -185,13 +185,13 @@ class CI_Cache_redis extends CI_Driver * @return void * @see Redis::connect() */ - private function _setup_redis() + protected function _setup_redis() { $config = array(); $CI =& get_instance(); if ($CI->config->load('redis', TRUE, TRUE)) - { + { $config += $CI->config->item('redis'); } @@ -208,7 +208,8 @@ class CI_Cache_redis extends CI_Driver show_error('Redis connection refused. ' . $e->getMessage()); } - if (isset($config['password'])) { + if (isset($config['password'])) + { $this->_redis->auth($config['password']); } } -- cgit v1.2.3-24-g4f1b From 9e674f74ec4f36f11f30e2f84a48ef6cea33a9d9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 21:02:52 +0300 Subject: Cleanup the new Redis cache driver and add a changelog entry for it --- system/libraries/Cache/Cache.php | 2 +- system/libraries/Cache/drivers/Cache_redis.php | 109 ++++++++++++++----------- 2 files changed, 63 insertions(+), 48 deletions(-) (limited to 'system/libraries/Cache') 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 -- cgit v1.2.3-24-g4f1b From c9195a75e7d3d06524c9a5ce97f4f4c30c69019b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 03:49:03 +0300 Subject: Add changelog for pull #1017 --- system/libraries/Cache/drivers/Cache_file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 1b57c8929..08231963e 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -26,7 +26,7 @@ */ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter File Caching Class * * @package CodeIgniter * @subpackage Libraries @@ -202,4 +202,4 @@ class CI_Cache_file extends CI_Driver { } /* End of file Cache_file.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ee112692c0e893dbe1d03b7ee62da6860db7310c Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 14 Jun 2012 15:32:17 -0300 Subject: A TTL of 0 will keep the cache persistant. --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 08231963e..028875b7d 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -73,7 +73,7 @@ class CI_Cache_file extends CI_Driver { $data = unserialize(file_get_contents($this->_cache_path.$id)); - if (time() > $data['time'] + $data['ttl']) + if ($data['ttl'] > 0 AND time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; -- cgit v1.2.3-24-g4f1b From 0159ae7d492cccca7a30a2f5b5c2b107d399e7ea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 17 Jun 2012 02:33:43 +0300 Subject: AND -> && --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 028875b7d..37d77c268 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -73,7 +73,7 @@ class CI_Cache_file extends CI_Driver { $data = unserialize(file_get_contents($this->_cache_path.$id)); - if ($data['ttl'] > 0 AND time() > $data['time'] + $data['ttl']) + if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; -- cgit v1.2.3-24-g4f1b From fe8324934f4bd15c86460975d265f72362cbbb3a Mon Sep 17 00:00:00 2001 From: vlakoff Date: Fri, 13 Jul 2012 20:40:06 +0200 Subject: Some adjustments in inline documentation --- system/libraries/Cache/drivers/Cache_wincache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache') diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index 74048d564..89e9f77c8 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b