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.php26
-rw-r--r--system/libraries/Cache/drivers/Cache_redis.php18
-rw-r--r--system/libraries/Cache/drivers/Cache_wincache.php27
4 files changed, 74 insertions, 24 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 c22a36f4c..df02ca2d0 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -107,6 +107,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->_memcache_conf as $cache_server)
@@ -186,7 +187,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)
@@ -251,7 +252,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)
@@ -286,4 +287,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'));
}
-
}