summaryrefslogtreecommitdiffstats
path: root/system/libraries/Cache/drivers/Cache_memcached.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Cache/drivers/Cache_memcached.php')
-rw-r--r--system/libraries/Cache/drivers/Cache_memcached.php142
1 files changed, 71 insertions, 71 deletions
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index b90b561c9..111e2109d 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -68,6 +68,76 @@ class CI_Cache_memcached extends CI_Driver {
)
);
+ // ------------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * Setup Memcache(d)
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ // Try to load memcached server info from the config file.
+ $CI =& get_instance();
+ $defaults = $this->_memcache_conf['default'];
+
+ if ($CI->config->load('memcached', TRUE, TRUE))
+ {
+ if (is_array($CI->config->config['memcached']))
+ {
+ $this->_memcache_conf = array();
+
+ foreach ($CI->config->config['memcached'] as $name => $conf)
+ {
+ $this->_memcache_conf[$name] = $conf;
+ }
+ }
+ }
+
+ if (class_exists('Memcached', FALSE))
+ {
+ $this->_memcached = new Memcached();
+ }
+ elseif (class_exists('Memcache', FALSE))
+ {
+ $this->_memcached = new Memcache();
+ }
+ else
+ {
+ throw new RuntimeException('Cache: Failed to create Memcache(d) object; extension not loaded?');
+ }
+
+ foreach ($this->_memcache_conf as $cache_server)
+ {
+ isset($cache_server['hostname']) OR $cache_server['hostname'] = $defaults['host'];
+ 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')
+ {
+ // Third parameter is persistance and defaults to TRUE.
+ $this->_memcached->addServer(
+ $cache_server['hostname'],
+ $cache_server['port'],
+ TRUE,
+ $cache_server['weight']
+ );
+ }
+ else
+ {
+ $this->_memcached->addServer(
+ $cache_server['hostname'],
+ $cache_server['port'],
+ $cache_server['weight']
+ );
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+
/**
* Fetch from cache
*
@@ -205,75 +275,6 @@ class CI_Cache_memcached extends CI_Driver {
// ------------------------------------------------------------------------
/**
- * Setup memcached.
- *
- * @return bool
- */
- protected function _setup_memcached()
- {
- // Try to load memcached server info from the config file.
- $CI =& get_instance();
- $defaults = $this->_memcache_conf['default'];
-
- if ($CI->config->load('memcached', TRUE, TRUE))
- {
- if (is_array($CI->config->config['memcached']))
- {
- $this->_memcache_conf = array();
-
- foreach ($CI->config->config['memcached'] as $name => $conf)
- {
- $this->_memcache_conf[$name] = $conf;
- }
- }
- }
-
- if (class_exists('Memcached', FALSE))
- {
- $this->_memcached = new Memcached();
- }
- elseif (class_exists('Memcache', FALSE))
- {
- $this->_memcached = new Memcache();
- }
- else
- {
- log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?');
- return FALSE;
- }
-
- foreach ($this->_memcache_conf as $cache_server)
- {
- isset($cache_server['hostname']) OR $cache_server['hostname'] = $defaults['host'];
- 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')
- {
- // Third parameter is persistance and defaults to TRUE.
- $this->_memcached->addServer(
- $cache_server['hostname'],
- $cache_server['port'],
- TRUE,
- $cache_server['weight']
- );
- }
- else
- {
- $this->_memcached->addServer(
- $cache_server['hostname'],
- $cache_server['port'],
- $cache_server['weight']
- );
- }
- }
-
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
-
- /**
* Is supported
*
* Returns FALSE if memcached is not supported on the system.
@@ -289,7 +290,6 @@ class CI_Cache_memcached extends CI_Driver {
return FALSE;
}
- return $this->_setup_memcached();
+ return TRUE;
}
-
}