summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Cache')
-rw-r--r--system/libraries/Cache/drivers/Cache_apc.php27
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php34
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php18
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php27
4 files changed, 78 insertions, 28 deletions
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index dd18e7bc8..07ea8f474 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.php
@@ -49,6 +49,24 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class CI_Cache_apc extends CI_Driver {
/**
+ * Class constructor
+ *
+ * Only present so that an error message is logged
+ * if APC is not available.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ if ( ! $this->is_supported())
+ {
+ log_message('error', 'Cache: Failed to initialize APC; extension not loaded/enabled?');
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Get
*
* Look for a value in the cache. If it exists, return the data
@@ -198,13 +216,6 @@ class CI_Cache_apc extends CI_Driver {
*/
public function is_supported()
{
- if ( ! extension_loaded('apc') OR ! ini_get('apc.enabled'))
- {
- log_message('debug', 'The APC PHP extension must be loaded to use APC Cache.');
- return FALSE;
- }
-
- return TRUE;
+ return (extension_loaded('apc') && ini_get('apc.enabled'));
}
-
}
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 2d6236a6f..6dee1e8e4 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -99,6 +99,7 @@ class CI_Cache_memcached extends CI_Driver {
else
{
log_message('error', 'Cache: Failed to create Memcache(d) object; extension not loaded?');
+ return;
}
foreach ($this->_config as $cache_server)
@@ -107,7 +108,7 @@ class CI_Cache_memcached extends CI_Driver {
isset($cache_server['port']) OR $cache_server['port'] = $defaults['port'];
isset($cache_server['weight']) OR $cache_server['weight'] = $defaults['weight'];
- if (get_class($this->_memcached) === 'Memcache')
+ if ($this->_memcached instanceof Memcache)
{
// Third parameter is persistance and defaults to TRUE.
$this->_memcached->addServer(
@@ -117,7 +118,7 @@ class CI_Cache_memcached extends CI_Driver {
$cache_server['weight']
);
}
- else
+ elseif ($this->_memcached instanceof Memcached)
{
$this->_memcached->addServer(
$cache_server['hostname'],
@@ -161,11 +162,11 @@ class CI_Cache_memcached extends CI_Driver {
$data = array($data, time(), $ttl);
}
- if (get_class($this->_memcached) === 'Memcached')
+ if ($this->_memcached instanceof Memcached)
{
return $this->_memcached->set($id, $data, $ttl);
}
- elseif (get_class($this->_memcached) === 'Memcache')
+ elseif ($this->_memcached instanceof Memcache)
{
return $this->_memcached->set($id, $data, 0, $ttl);
}
@@ -178,7 +179,7 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Delete from Cache
*
- * @param mixed key to be deleted.
+ * @param mixed $id key to be deleted.
* @return bool true on success, false on failure
*/
public function delete($id)
@@ -243,7 +244,7 @@ class CI_Cache_memcached extends CI_Driver {
/**
* Get Cache Metadata
*
- * @param mixed key to get cache metadata on
+ * @param mixed $id key to get cache metadata on
* @return mixed FALSE on failure, array on success.
*/
public function get_metadata($id)
@@ -278,4 +279,25 @@ class CI_Cache_memcached extends CI_Driver {
{
return (extension_loaded('memcached') OR extension_loaded('memcache'));
}
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * Class destructor
+ *
+ * Closes the connection to Memcache(d) if present.
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if ($this->_memcached instanceof Memcache)
+ {
+ $this->_memcached->close();
+ }
+ elseif ($this->_memcached instanceof Memcached)
+ {
+ $this->_memcached->quit();
+ }
+ }
}
diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php
index 81b49e2fc..a58aaef4e 100644
--- a/system/libraries/Cache/drivers/Cache_redis.php
+++ b/system/libraries/Cache/drivers/Cache_redis.php
@@ -91,6 +91,12 @@ class CI_Cache_redis extends CI_Driver
*/
public function __construct()
{
+ if ( ! $this->is_supported())
+ {
+ log_message('error', 'Cache: Failed to create Redis object; extension not loaded?');
+ return;
+ }
+
$config = array();
$CI =& get_instance();
@@ -138,7 +144,7 @@ class CI_Cache_redis extends CI_Driver
/**
* Get cache
*
- * @param string Cache ID
+ * @param string $key Cache ID
* @return mixed
*/
public function get($key)
@@ -190,7 +196,7 @@ class CI_Cache_redis extends CI_Driver
/**
* Delete from cache
*
- * @param string Cache key
+ * @param string $key Cache key
* @return bool
*/
public function delete($key)
@@ -255,9 +261,9 @@ class CI_Cache_redis extends CI_Driver
/**
* Get cache driver info
*
- * @param string Not supported in Redis.
- * Only included in order to offer a
- * consistent cache API.
+ * @param string $type Not supported in Redis.
+ * Only included in order to offer a
+ * consistent cache API.
* @return array
* @see Redis::info()
*/
@@ -271,7 +277,7 @@ class CI_Cache_redis extends CI_Driver
/**
* Get cache metadata
*
- * @param string Cache key
+ * @param string $key Cache key
* @return array
*/
public function get_metadata($key)
diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php
index f66080514..d6a0d4fb6 100644
--- a/system/libraries/Cache/drivers/Cache_wincache.php
+++ b/system/libraries/Cache/drivers/Cache_wincache.php
@@ -52,6 +52,24 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class CI_Cache_wincache extends CI_Driver {
/**
+ * Class constructor
+ *
+ * Only present so that an error message is logged
+ * if APC is not available.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ if ( ! $this->is_supported())
+ {
+ log_message('error', 'Cache: Failed to initialize Wincache; extension not loaded/enabled?');
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
* Get
*
* Look for a value in the cache. If it exists, return the data,
@@ -194,13 +212,6 @@ class CI_Cache_wincache extends CI_Driver {
*/
public function is_supported()
{
- if ( ! extension_loaded('wincache') OR ! ini_get('wincache.ucenabled'))
- {
- log_message('debug', 'The Wincache PHP extension must be loaded to use Wincache Cache.');
- return FALSE;
- }
-
- return TRUE;
+ return (extension_loaded('wincache') && ini_get('wincache.ucenabled'));
}
-
}