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