From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Cache/Cache.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 61e7aa761..269bf9b2d 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -1,13 +1,25 @@ - Date: Sun, 25 Dec 2011 00:31:29 -0600 Subject: Fixing soft tabs in a few files. --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 269bf9b2d..c296fa770 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -155,7 +155,7 @@ class CI_Cache extends CI_Driver_Library { * @return void */ private function _initialize($config) - { + { $default_config = array( 'adapter', 'memcached' -- cgit v1.2.3-24-g4f1b From 7d4ea07ae5dee6abb0116e76ec9c9a876a02e610 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 19:23:50 +0200 Subject: Improve the Cache library --- system/libraries/Cache/Cache.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index c296fa770..87253739c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -1,13 +1,13 @@ -{$this->_adapter}->get($id); } @@ -124,7 +124,7 @@ class CI_Cache extends CI_Driver_Library { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -132,7 +132,7 @@ class CI_Cache extends CI_Driver_Library { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -143,7 +143,7 @@ class CI_Cache extends CI_Driver_Library { { return $this->{$this->_adapter}->get_metadata($id); } - + // ------------------------------------------------------------------------ /** @@ -151,7 +151,7 @@ class CI_Cache extends CI_Driver_Library { * * Initialize class properties based on the configuration array. * - * @param array + * @param array * @return void */ private function _initialize($config) @@ -219,10 +219,10 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - + // ------------------------------------------------------------------------ } // End Class /* End of file Cache.php */ -/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file +/* Location: ./system/libraries/Cache/Cache.php */ -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 87253739c..2e78a6660 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2011 EllisLab, Inc. + * @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 -- cgit v1.2.3-24-g4f1b 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') 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) -- cgit v1.2.3-24-g4f1b From 03a57655f3cdc6c0b9f717f4466a4547247729d3 Mon Sep 17 00:00:00 2001 From: Mike Davies Date: Wed, 29 Feb 2012 17:52:36 -0500 Subject: Added support for Wincache when running CI on Windows boxes Wincache is directly analogous to APC, except with less problems on a Windows environment. Performance wise they are almost identical (for user mode caching at least). Need to have the Wincache PHP module downloaded from http://www.iis.net/download/wincacheforphp. --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 2e78a6660..e9cc1101c 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_dummy', 'cache_wincache' ); protected $_cache_path = NULL; // Path of cache files (if file-based cache) -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 2e78a6660..60998e3b8 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.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 From 6b535f51fcb94e0a645fda0d0356f4748076877e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Mar 2012 22:19:13 +0200 Subject: Fix some spaces and alignments in the new Wincache driver --- system/libraries/Cache/Cache.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index b89e5ab6f..7642a5270 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -39,20 +39,17 @@ class CI_Cache extends CI_Driver_Library { protected $valid_drivers = array( - 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy', 'cache_wincache' - ); - - protected $_cache_path = NULL; // Path of cache files (if file-based cache) - protected $_adapter = 'dummy'; + 'cache_apc', + 'cache_file', + 'cache_memcached', + 'cache_dummy', + 'cache_wincache' + ); + + protected $_cache_path = NULL; // Path of cache files (if file-based cache) + protected $_adapter = 'dummy'; protected $_backup_driver; - // ------------------------------------------------------------------------ - - /** - * Constructor - * - * @param array - */ public function __construct($config = array()) { if ( ! empty($config)) -- cgit v1.2.3-24-g4f1b From b24b033a9c285c98802fbd7bf16d486e355e2f97 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 15:34:39 +0300 Subject: Switch private methods and properties to protected and cleanup the Cache library and drivers --- system/libraries/Cache/Cache.php | 109 +++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 62 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 7642a5270..f98241617 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Caching Class * @@ -50,11 +48,37 @@ class CI_Cache extends CI_Driver_Library { protected $_adapter = 'dummy'; protected $_backup_driver; + /** + * Constructor + * + * Initialize class properties based on the configuration array. + * + * @param array + * @return void + */ public function __construct($config = array()) { - if ( ! empty($config)) + $default_config = array( + 'adapter', + 'memcached' + ); + + foreach ($default_config as $key) { - $this->_initialize($config); + if (isset($config[$key])) + { + $param = '_'.$key; + + $this->{$param} = $config[$key]; + } + } + + if (isset($config['backup'])) + { + if (in_array('cache_'.$config['backup'], $this->valid_drivers)) + { + $this->_backup_driver = $config['backup']; + } } } @@ -63,11 +87,11 @@ class CI_Cache extends CI_Driver_Library { /** * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string - * @return mixed value that is stored/FALSE on failure + * @param string + * @return mixed value that is stored/FALSE on failure */ public function get($id) { @@ -79,11 +103,10 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data - * - * @return boolean true on success/false on failure + * @param string Unique Key + * @param mixed Data to store + * @param int Length of time (in seconds) to cache the data + * @return bool true on success/false on failure */ public function save($id, $data, $ttl = 60) { @@ -95,8 +118,8 @@ class CI_Cache extends CI_Driver_Library { /** * Delete from Cache * - * @param mixed unique identifier of the item in the cache - * @return boolean true on success/false on failure + * @param mixed unique identifier of the item in the cache + * @return bool true on success/false on failure */ public function delete($id) { @@ -108,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { /** * Clean the cache * - * @return boolean false on failure/true on success + * @return bool false on failure/true on success */ public function clean() { @@ -120,8 +143,8 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Info * - * @param string user/filehits - * @return mixed array on success, false on failure + * @param string user/filehits + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -133,8 +156,8 @@ class CI_Cache extends CI_Driver_Library { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed return value from child method + * @param mixed key to get cache metadata on + * @return mixed return value from child method */ public function get_metadata($id) { @@ -143,47 +166,11 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ - /** - * Initialize - * - * Initialize class properties based on the configuration array. - * - * @param array - * @return void - */ - private function _initialize($config) - { - $default_config = array( - 'adapter', - 'memcached' - ); - - foreach ($default_config as $key) - { - if (isset($config[$key])) - { - $param = '_'.$key; - - $this->{$param} = $config[$key]; - } - } - - if (isset($config['backup'])) - { - if (in_array('cache_'.$config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } - } - } - - // ------------------------------------------------------------------------ - /** * Is the requested driver supported in this environment? * - * @param string The driver to test. - * @return array + * @param string The driver to test. + * @return array */ public function is_supported($driver) { @@ -202,8 +189,8 @@ class CI_Cache extends CI_Driver_Library { /** * __get() * - * @param child - * @return object + * @param child + * @return object */ public function __get($child) { @@ -217,9 +204,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - // ------------------------------------------------------------------------ } -// End Class /* End of file Cache.php */ -/* Location: ./system/libraries/Cache/Cache.php */ +/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0688ac9ad88a03f1c56cfcd9e3c475b83301344d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 20 Apr 2012 10:25:04 -0400 Subject: Start comment cleanup of libraries --- system/libraries/Cache/Cache.php | 48 +++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index f98241617..409323def 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -36,16 +36,38 @@ */ class CI_Cache extends CI_Driver_Library { - protected $valid_drivers = array( - 'cache_apc', - 'cache_file', - 'cache_memcached', - 'cache_dummy', - 'cache_wincache' - ); - - protected $_cache_path = NULL; // Path of cache files (if file-based cache) - protected $_adapter = 'dummy'; + /** + * Valid cache drivers + * + * @var array + */ + protected $valid_drivers = array( + 'cache_apc', + 'cache_file', + 'cache_memcached', + 'cache_dummy', + 'cache_wincache' + ); + + /** + * Path of cache files (if file-based cache) + * + * @var string + */ + protected $_cache_path = NULL; + + /** + * Reference to the driver + * + * @var mixe + */ + protected $_adapter = 'dummy'; + + /** + * Fallback driver + * + * @param string + */ protected $_backup_driver; /** @@ -59,9 +81,9 @@ class CI_Cache extends CI_Driver_Library { public function __construct($config = array()) { $default_config = array( - 'adapter', - 'memcached' - ); + 'adapter', + 'memcached' + ); foreach ($default_config as $key) { -- 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/Cache.php') 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/Cache.php') 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 b82bc3a016ce01dfeb993da5918853625a40af86 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 09:12:58 -0400 Subject: Fix Cache, Image_lib and Log libraries --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 409323def..0493d5a6e 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -59,7 +59,7 @@ class CI_Cache extends CI_Driver_Library { /** * Reference to the driver * - * @var mixe + * @var mixed */ protected $_adapter = 'dummy'; -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Cache/Cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 0493d5a6e..ba732ee8e 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -55,14 +55,14 @@ class CI_Cache extends CI_Driver_Library { * @var string */ protected $_cache_path = NULL; - + /** * Reference to the driver * * @var mixed */ protected $_adapter = 'dummy'; - + /** * Fallback driver * -- 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/Cache.php') 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 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') 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 -- cgit v1.2.3-24-g4f1b From 58c2b10eff196d6e7e4c678a3d7ef13bbc030124 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 26 Oct 2012 14:42:29 +0300 Subject: Implement cache key prefixing (as suggested in #1197) and update the Cache docs --- system/libraries/Cache/Cache.php | 58 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 4395cf411..ce71445df 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -41,7 +41,7 @@ class CI_Cache extends CI_Driver_Library { * * @var array */ - protected $valid_drivers = array( + protected $valid_drivers = array( 'cache_apc', 'cache_dummy', 'cache_file', @@ -67,16 +67,23 @@ class CI_Cache extends CI_Driver_Library { /** * Fallback driver * - * @param string + * @var string */ protected $_backup_driver = 'dummy'; + /** + * Cache key prefix + * + * @var string + */ + public $key_prefix = ''; + /** * Constructor * * Initialize class properties based on the configuration array. * - * @param array + * @param array $config = array() * @return void */ public function __construct($config = array()) @@ -96,12 +103,11 @@ class CI_Cache extends CI_Driver_Library { } } - if (isset($config['backup'])) + isset($config['key_prefix']) AND $this->key_prefix = $config['key_prefix']; + + if (isset($config['backup']) && in_array('cache_'.$config['backup'], $this->valid_drivers)) { - if (in_array('cache_'.$config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } + $this->_backup_driver = $config['backup']; } // If the specified adapter isn't available, check the backup. @@ -129,12 +135,12 @@ class CI_Cache extends CI_Driver_Library { * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string - * @return mixed value that is stored/FALSE on failure + * @param string $id + * @return mixed value matching $id or FALSE on failure */ public function get($id) { - return $this->{$this->_adapter}->get($id); + return $this->{$this->_adapter}->get($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -142,14 +148,14 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data - * @return bool true on success/false on failure + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl = 60 Cache TTL (in seconds) + * @return bool TRUE on success, FALSE on failure */ public function save($id, $data, $ttl = 60) { - return $this->{$this->_adapter}->save($id, $data, $ttl); + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl); } // ------------------------------------------------------------------------ @@ -157,12 +163,12 @@ class CI_Cache extends CI_Driver_Library { /** * Delete from Cache * - * @param mixed unique identifier of the item in the cache - * @return bool true on success/false on failure + * @param string $id Cache ID + * @return bool TRUE on success, FALSE on failure */ public function delete($id) { - return $this->{$this->_adapter}->delete($id); + return $this->{$this->_adapter}->delete($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -170,7 +176,7 @@ class CI_Cache extends CI_Driver_Library { /** * Clean the cache * - * @return bool false on failure/true on success + * @return bool TRUE on success, FALSE on failure */ public function clean() { @@ -182,8 +188,8 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Info * - * @param string user/filehits - * @return mixed array on success, false on failure + * @param string $type = 'user' user/filehits + * @return mixed array containing cache info on success OR FALSE on failure */ public function cache_info($type = 'user') { @@ -195,12 +201,12 @@ class CI_Cache extends CI_Driver_Library { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed return value from child method + * @param string $id key to get cache metadata on + * @return mixed cache item metadata */ public function get_metadata($id) { - return $this->{$this->_adapter}->get_metadata($id); + return $this->{$this->_adapter}->get_metadata($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -208,7 +214,7 @@ class CI_Cache extends CI_Driver_Library { /** * Is the requested driver supported in this environment? * - * @param string The driver to test. + * @param string $driver The driver to test * @return array */ public function is_supported($driver) -- cgit v1.2.3-24-g4f1b From 94b1f76780e4dbc67ff4b43a98f2cb4e23c01a29 Mon Sep 17 00:00:00 2001 From: vkeranov Date: Sat, 27 Oct 2012 18:19:59 +0300 Subject: Style guide... --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index ce71445df..7ec2380a5 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -103,7 +103,7 @@ class CI_Cache extends CI_Driver_Library { } } - isset($config['key_prefix']) AND $this->key_prefix = $config['key_prefix']; + isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; if (isset($config['backup']) && in_array('cache_'.$config['backup'], $this->valid_drivers)) { -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Cache/Cache.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 7ec2380a5..e76fdc557 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -1,4 +1,4 @@ - Date: Sat, 24 Nov 2012 18:41:13 -0500 Subject: Added support for extending individual driver classes and driver unit tests Signed-off-by: dchill42 --- system/libraries/Cache/Cache.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index e76fdc557..48bd9581a 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -43,12 +43,12 @@ class CI_Cache extends CI_Driver_Library { * @var array */ protected $valid_drivers = array( - 'cache_apc', - 'cache_dummy', - 'cache_file', - 'cache_memcached', - 'cache_redis', - 'cache_wincache' + 'apc', + 'dummy', + 'file', + 'memcached', + 'redis', + 'wincache' ); /** -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 48bd9581a..e1089f755 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 -- cgit v1.2.3-24-g4f1b From 516527c1dc03de4192966c79086d4ca8eaacc77c Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Wed, 24 Jul 2013 10:51:04 -0400 Subject: Cache Driver - Backup Never Loaded The condition that checks to see if the backup driver input is valid was prefixing the input with "cache_". Since the valid driver values don't have this prefix, the condition was always returning FALSE and the backup drivers were never being loaded. I've removed the prefix in the condition and added a debug log message for when the backup driver is used. --- system/libraries/Cache/Cache.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index e1089f755..537897eaf 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -106,7 +106,7 @@ class CI_Cache extends CI_Driver_Library { isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; - if (isset($config['backup']) && in_array('cache_'.$config['backup'], $this->valid_drivers)) + if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) { $this->_backup_driver = $config['backup']; } @@ -123,6 +123,7 @@ class CI_Cache extends CI_Driver_Library { else { // Backup is supported. Set it to primary. + log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.'); $this->_adapter = $this->_backup_driver; } } -- cgit v1.2.3-24-g4f1b From 43d7fa73534c07d10a88ec120c0938d0d00a184e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 17:29:45 +0200 Subject: Implement atomic increment/decrement in Cache library Requested via issue #109 Supersedes PR #241 --- system/libraries/Cache/Cache.php | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 537897eaf..2dffa350c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -150,14 +150,15 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string $id Cache ID - * @param mixed $data Data to store - * @param int $ttl = 60 Cache TTL (in seconds) + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Cache TTL (in seconds) + * @param bool $raw Whether to store the raw value * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { - return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl); + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); } // ------------------------------------------------------------------------ @@ -175,6 +176,34 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->{$this->_adapter}->increment($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->{$this->_adapter}->decrement($id, $offset); + } + + // ------------------------------------------------------------------------ + /** * Clean the cache * -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 2dffa350c..f9768b10c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Cache/Cache.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index f9768b10c..ec2626a1d 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * 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. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 2.0 + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 2.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Cache/Cache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index ec2626a1d..bee0c068b 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 2.0.0 -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Cache/Cache.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index bee0c068b..40ac70103 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -272,6 +272,3 @@ class CI_Cache extends CI_Driver_Library { } } - -/* End of file Cache.php */ -/* Location: ./system/libraries/Cache/Cache.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 24812132d7aa039bbdca1f150a850dc776ce7bd7 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Thu, 23 Apr 2015 15:11:03 -0400 Subject: Updates the fallback driver variable name to match the config option name. --- system/libraries/Cache/Cache.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 40ac70103..fd49f33ab 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -81,7 +81,7 @@ class CI_Cache extends CI_Driver_Library { * * @var string */ - protected $_backup_driver = 'dummy'; + protected $_backup = 'dummy'; /** * Cache key prefix @@ -119,23 +119,23 @@ class CI_Cache extends CI_Driver_Library { if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) { - $this->_backup_driver = $config['backup']; + $this->_backup = $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)) + if ( ! $this->is_supported($this->_backup)) { // 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.'); + log_message('error', 'Cache adapter "'.$this->_adapter.'" and backup "'.$this->_backup.'" are both unavailable. Cache is now using "Dummy" adapter.'); $this->_adapter = 'dummy'; } else { // Backup is supported. Set it to primary. - log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.'); - $this->_adapter = $this->_backup_driver; + log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup.'" backup adapter.'); + $this->_adapter = $this->_backup; } } } -- cgit v1.2.3-24-g4f1b From 229a546efbbc0e6d70c2ea764d74b9c1c57516c2 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Thu, 23 Apr 2015 15:38:06 -0400 Subject: Cache Library Defaults Fixed - Comments! - Updates the cache library to validate *both* adapters. - No longer attempts to set an undefined "memcached" class variable. - $key variable renamed to $driver_type (more descriptive). --- system/libraries/Cache/Cache.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index fd49f33ab..5d32240ce 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -100,28 +100,19 @@ class CI_Cache extends CI_Driver_Library { */ public function __construct($config = array()) { - $default_config = array( - 'adapter', - 'memcached' - ); - - foreach ($default_config as $key) + // Loop through the available driver types and overwrite them as they're found. + foreach (array('adapter', 'backup') as $driver_type) { - if (isset($config[$key])) + if (isset($config[$driver_type]) && in_array($config[$driver_type], $this->valid_drivers)) { - $param = '_'.$key; - - $this->{$param} = $config[$key]; + $option = '_'.$driver_type; + $this->{$option} = $config[$driver_type]; } } + // Overwrite the default key prefix. isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; - if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) - { - $this->_backup = $config['backup']; - } - // If the specified adapter isn't available, check the backup. if ( ! $this->is_supported($this->_adapter)) { -- cgit v1.2.3-24-g4f1b From bf2ca381da2f63439f23df91369a68dccae6ea4b Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Thu, 23 Apr 2015 15:44:37 -0400 Subject: Renames $_adapter to $_driver. It's what we call it everywhere else. --- system/libraries/Cache/Cache.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 5d32240ce..39d05d930 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -74,7 +74,7 @@ class CI_Cache extends CI_Driver_Library { * * @var mixed */ - protected $_adapter = 'dummy'; + protected $_driver = 'dummy'; /** * Fallback driver @@ -114,19 +114,19 @@ class CI_Cache extends CI_Driver_Library { isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; // If the specified adapter isn't available, check the backup. - if ( ! $this->is_supported($this->_adapter)) + if ( ! $this->is_supported($this->_driver)) { if ( ! $this->is_supported($this->_backup)) { // Backup isn't supported either. Default to 'Dummy' driver. - log_message('error', 'Cache adapter "'.$this->_adapter.'" and backup "'.$this->_backup.'" are both unavailable. Cache is now using "Dummy" adapter.'); - $this->_adapter = 'dummy'; + log_message('error', 'Cache adapter "'.$this->_driver.'" and backup "'.$this->_backup.'" are both unavailable. Cache is now using "Dummy" adapter.'); + $this->_driver = 'dummy'; } else { // Backup is supported. Set it to primary. - log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup.'" backup adapter.'); - $this->_adapter = $this->_backup; + log_message('debug', 'Cache adapter "'.$this->_driver.'" is unavailable. Falling back to "'.$this->_backup.'" backup adapter.'); + $this->_driver = $this->_backup; } } } @@ -144,7 +144,7 @@ class CI_Cache extends CI_Driver_Library { */ public function get($id) { - return $this->{$this->_adapter}->get($this->key_prefix.$id); + return $this->{$this->_driver}->get($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -160,7 +160,7 @@ class CI_Cache extends CI_Driver_Library { */ public function save($id, $data, $ttl = 60, $raw = FALSE) { - return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); + return $this->{$this->_driver}->save($this->key_prefix.$id, $data, $ttl, $raw); } // ------------------------------------------------------------------------ @@ -173,7 +173,7 @@ class CI_Cache extends CI_Driver_Library { */ public function delete($id) { - return $this->{$this->_adapter}->delete($this->key_prefix.$id); + return $this->{$this->_driver}->delete($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -187,7 +187,7 @@ class CI_Cache extends CI_Driver_Library { */ public function increment($id, $offset = 1) { - return $this->{$this->_adapter}->increment($id, $offset); + return $this->{$this->_driver}->increment($id, $offset); } // ------------------------------------------------------------------------ @@ -201,7 +201,7 @@ class CI_Cache extends CI_Driver_Library { */ public function decrement($id, $offset = 1) { - return $this->{$this->_adapter}->decrement($id, $offset); + return $this->{$this->_driver}->decrement($id, $offset); } // ------------------------------------------------------------------------ @@ -213,7 +213,7 @@ class CI_Cache extends CI_Driver_Library { */ public function clean() { - return $this->{$this->_adapter}->clean(); + return $this->{$this->_driver}->clean(); } // ------------------------------------------------------------------------ @@ -226,7 +226,7 @@ class CI_Cache extends CI_Driver_Library { */ public function cache_info($type = 'user') { - return $this->{$this->_adapter}->cache_info($type); + return $this->{$this->_driver}->cache_info($type); } // ------------------------------------------------------------------------ @@ -239,7 +239,7 @@ class CI_Cache extends CI_Driver_Library { */ public function get_metadata($id) { - return $this->{$this->_adapter}->get_metadata($this->key_prefix.$id); + return $this->{$this->_driver}->get_metadata($this->key_prefix.$id); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 0416a7f859e1ee6df557644b36ca10cfd356d224 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Fri, 24 Apr 2015 10:25:38 -0400 Subject: Reverts previous variable renaming and removes the foreach loop in favor of a simple if condition. --- system/libraries/Cache/Cache.php | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 39d05d930..73dec72ab 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -74,14 +74,14 @@ class CI_Cache extends CI_Driver_Library { * * @var mixed */ - protected $_driver = 'dummy'; + protected $_adapter = 'dummy'; /** * Fallback driver * * @var string */ - protected $_backup = 'dummy'; + protected $_backup_driver = 'dummy'; /** * Cache key prefix @@ -100,33 +100,32 @@ class CI_Cache extends CI_Driver_Library { */ public function __construct($config = array()) { - // Loop through the available driver types and overwrite them as they're found. - foreach (array('adapter', 'backup') as $driver_type) + if (isset($config['adapter']) && in_array($config['adapter'], $this->valid_drivers)) { - if (isset($config[$driver_type]) && in_array($config[$driver_type], $this->valid_drivers)) - { - $option = '_'.$driver_type; - $this->{$option} = $config[$driver_type]; - } + $this->_adapter = $config['adapter']; + } + + if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) + { + $this->_backup_driver = $config['backup']; } - // Overwrite the default key prefix. isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; // If the specified adapter isn't available, check the backup. - if ( ! $this->is_supported($this->_driver)) + if ( ! $this->is_supported($this->_adapter)) { - if ( ! $this->is_supported($this->_backup)) + if ( ! $this->is_supported($this->_backup_driver)) { // Backup isn't supported either. Default to 'Dummy' driver. - log_message('error', 'Cache adapter "'.$this->_driver.'" and backup "'.$this->_backup.'" are both unavailable. Cache is now using "Dummy" adapter.'); - $this->_driver = 'dummy'; + 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. - log_message('debug', 'Cache adapter "'.$this->_driver.'" is unavailable. Falling back to "'.$this->_backup.'" backup adapter.'); - $this->_driver = $this->_backup; + log_message('debug', 'Cache adapter "'.$this->_adapter.'" is unavailable. Falling back to "'.$this->_backup_driver.'" backup adapter.'); + $this->_adapter = $this->_backup_driver; } } } @@ -144,7 +143,7 @@ class CI_Cache extends CI_Driver_Library { */ public function get($id) { - return $this->{$this->_driver}->get($this->key_prefix.$id); + return $this->{$this->_adapter}->get($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -160,7 +159,7 @@ class CI_Cache extends CI_Driver_Library { */ public function save($id, $data, $ttl = 60, $raw = FALSE) { - return $this->{$this->_driver}->save($this->key_prefix.$id, $data, $ttl, $raw); + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); } // ------------------------------------------------------------------------ @@ -173,7 +172,7 @@ class CI_Cache extends CI_Driver_Library { */ public function delete($id) { - return $this->{$this->_driver}->delete($this->key_prefix.$id); + return $this->{$this->_adapter}->delete($this->key_prefix.$id); } // ------------------------------------------------------------------------ @@ -187,7 +186,7 @@ class CI_Cache extends CI_Driver_Library { */ public function increment($id, $offset = 1) { - return $this->{$this->_driver}->increment($id, $offset); + return $this->{$this->_adapter}->increment($id, $offset); } // ------------------------------------------------------------------------ @@ -201,7 +200,7 @@ class CI_Cache extends CI_Driver_Library { */ public function decrement($id, $offset = 1) { - return $this->{$this->_driver}->decrement($id, $offset); + return $this->{$this->_adapter}->decrement($id, $offset); } // ------------------------------------------------------------------------ @@ -213,7 +212,7 @@ class CI_Cache extends CI_Driver_Library { */ public function clean() { - return $this->{$this->_driver}->clean(); + return $this->{$this->_adapter}->clean(); } // ------------------------------------------------------------------------ @@ -226,7 +225,7 @@ class CI_Cache extends CI_Driver_Library { */ public function cache_info($type = 'user') { - return $this->{$this->_driver}->cache_info($type); + return $this->{$this->_adapter}->cache_info($type); } // ------------------------------------------------------------------------ @@ -239,7 +238,7 @@ class CI_Cache extends CI_Driver_Library { */ public function get_metadata($id) { - return $this->{$this->_driver}->get_metadata($this->key_prefix.$id); + return $this->{$this->_adapter}->get_metadata($this->key_prefix.$id); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From b7661228c22c180cdf289300c88825dafeda39d9 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Mon, 27 Apr 2015 11:54:08 -0400 Subject: Adds error-level log messages when invalid adapters are set. --- system/libraries/Cache/Cache.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 73dec72ab..ff68a4fd8 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -104,11 +104,19 @@ class CI_Cache extends CI_Driver_Library { { $this->_adapter = $config['adapter']; } + elseif (! in_array($config['adapter'], $this->valid_drivers)) + { + log_message('error', 'Cache adapter "'.$config['adapter'].'" is invalid.'); + } if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) { $this->_backup_driver = $config['backup']; } + elseif (! in_array($config['backup'], $this->valid_drivers)) + { + log_message('error', 'Cache backup adapter "'.$config['backup'].'" is invalid.'); + } isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; -- cgit v1.2.3-24-g4f1b From ef0173db881f326db14e00cb333b9059349fc9a3 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Tue, 28 Apr 2015 10:33:05 -0400 Subject: Removed extra adapter validation. Adapter validation already happens in the system Driver library. --- system/libraries/Cache/Cache.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index ff68a4fd8..215a7c528 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -100,24 +100,8 @@ class CI_Cache extends CI_Driver_Library { */ public function __construct($config = array()) { - if (isset($config['adapter']) && in_array($config['adapter'], $this->valid_drivers)) - { - $this->_adapter = $config['adapter']; - } - elseif (! in_array($config['adapter'], $this->valid_drivers)) - { - log_message('error', 'Cache adapter "'.$config['adapter'].'" is invalid.'); - } - - if (isset($config['backup']) && in_array($config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } - elseif (! in_array($config['backup'], $this->valid_drivers)) - { - log_message('error', 'Cache backup adapter "'.$config['backup'].'" is invalid.'); - } - + isset($config['adapter']) && $this->_adapter = $config['adapter']; + isset($config['backup']) && $this->_backup_driver = $config['backup']; isset($config['key_prefix']) && $this->key_prefix = $config['key_prefix']; // If the specified adapter isn't available, check the backup. -- cgit v1.2.3-24-g4f1b From 070ce056047f7624ceb95a1da2a34fc96bfa0868 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Jun 2015 13:24:11 +0300 Subject: A small optimization in CI_Cache::is_supported() As it was, the static variable was always re-set to an empty array --- system/libraries/Cache/Cache.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 215a7c528..06403b6e9 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -243,14 +243,13 @@ class CI_Cache extends CI_Driver_Library { */ public function is_supported($driver) { - static $support = array(); + static $support; - if ( ! isset($support[$driver])) + if ( ! isset($support, $support[$driver])) { $support[$driver] = $this->{$driver}->is_supported(); } return $support[$driver]; } - } -- cgit v1.2.3-24-g4f1b From 63b0c26d9d7e6b064145f629ecae5bda5f43fec6 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Sun, 5 Jul 2015 22:07:58 +0800 Subject: supported key_prefix on `increment` and `decrement` --- system/libraries/Cache/Cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 06403b6e9..0c87a5628 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -178,7 +178,7 @@ class CI_Cache extends CI_Driver_Library { */ public function increment($id, $offset = 1) { - return $this->{$this->_adapter}->increment($id, $offset); + return $this->{$this->_adapter}->increment($this->key_prefix.$id, $offset); } // ------------------------------------------------------------------------ @@ -192,7 +192,7 @@ class CI_Cache extends CI_Driver_Library { */ public function decrement($id, $offset = 1) { - return $this->{$this->_adapter}->decrement($id, $offset); + return $this->{$this->_adapter}->decrement($this->key_prefix.$id, $offset); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Cache/Cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 0c87a5628..023ad02bb 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 2.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 023ad02bb..64377de50 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 2.0.0 * @filesource */ -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Cache/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 64377de50..349af1579 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Cache/Cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Cache/Cache.php') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 349af1579..267dffb09 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 2.0.0 -- cgit v1.2.3-24-g4f1b