From 831c0d19569eb17cfad49f9dc40aa310e23e57b7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 27 Jan 2013 00:30:08 +0100 Subject: [PATCH] Added support for "memcached" (dropped "memcache") --- com.woltlab.wcf/option.xml | 20 ++--- .../lib/acp/page/CacheListPage.class.php | 2 +- .../cache/source/MemcacheAdapter.class.php | 65 --------------- .../cache/source/MemcachedAdapter.class.php | 80 +++++++++++++++++++ ...ass.php => MemcachedCacheSource.class.php} | 30 +++---- wcfsetup/install/lang/de.xml | 12 +-- 6 files changed, 112 insertions(+), 97 deletions(-) delete mode 100644 wcfsetup/install/files/lib/system/cache/source/MemcacheAdapter.class.php create mode 100644 wcfsetup/install/files/lib/system/cache/source/MemcachedAdapter.class.php rename wcfsetup/install/files/lib/system/cache/source/{MemcacheCacheSource.class.php => MemcachedCacheSource.class.php} (81%) diff --git a/com.woltlab.wcf/option.xml b/com.woltlab.wcf/option.xml index 0e1e37861b..9943fb60bc 100644 --- a/com.woltlab.wcf/option.xml +++ b/com.woltlab.wcf/option.xml @@ -69,7 +69,7 @@ general.cache - + general.cache @@ -385,22 +385,22 @@ debug:mail_debug_logfile_path,!mail_use_f_param,!mail_smtp_host,!mail_smtp_port, radioButton - + - - diff --git a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php index 9e385dfada..f3750ed014 100755 --- a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php @@ -87,7 +87,7 @@ class CacheListPage extends AbstractPage { } break; - case 'wcf\system\cache\source\MemcacheCacheSource': + case 'wcf\system\cache\source\MemcachedCacheSource': // set version $this->cacheData['version'] = WCF_VERSION; diff --git a/wcfsetup/install/files/lib/system/cache/source/MemcacheAdapter.class.php b/wcfsetup/install/files/lib/system/cache/source/MemcacheAdapter.class.php deleted file mode 100644 index 174a6f9b29..0000000000 --- a/wcfsetup/install/files/lib/system/cache/source/MemcacheAdapter.class.php +++ /dev/null @@ -1,65 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.cache.source - * @category Community Framework - */ -class MemcacheAdapter extends SingletonFactory { - /** - * memcache object - * @var Memcache - */ - private $memcache = null; - - /** - * @see wcf\system\SingletonFactory::init() - */ - protected function init() { - if (!class_exists('Memcache')) { - throw new SystemException('memcache support is not enabled.'); - } - - // init memcache - $this->memcache = new \Memcache(); - - // add servers - $servers = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHE_HOST)); - foreach ($servers as $server) { - $server = StringUtil::trim($server); - if (!empty($server)) { - $host = $server; - $port = 11211; // default memcache port - // get port - if (strpos($host, ':')) { - $parsedHost = explode(':', $host); - $host = $parsedHost[0]; - $port = $parsedHost[1]; - } - - $this->memcache->addServer($host, $port, CACHE_SOURCE_MEMCACHE_USE_PCONNECT); - } - } - - // test connection - $this->memcache->get('testing'); - } - - /** - * Returns the memcache object. - * - * @return Memcache - */ - public function getMemcache() { - return $this->memcache; - } -} diff --git a/wcfsetup/install/files/lib/system/cache/source/MemcachedAdapter.class.php b/wcfsetup/install/files/lib/system/cache/source/MemcachedAdapter.class.php new file mode 100644 index 0000000000..36e235bd31 --- /dev/null +++ b/wcfsetup/install/files/lib/system/cache/source/MemcachedAdapter.class.php @@ -0,0 +1,80 @@ + + * @package com.woltlab.wcf + * @subpackage system.cache.source + * @category Community Framework + */ +class MemcachedAdapter extends SingletonFactory { + /** + * memcached object + * @var \Memcached + */ + private $memcached = null; + + /** + * @see wcf\system\SingletonFactory::init() + */ + protected function init() { + if (!class_exists('Memcached')) { + throw new SystemException('memcached support is not enabled.'); + } + + // init memcached + if (CACHE_SOURCE_MEMCACHED_USE_PCONNECT) { + $this->memcached = new \Memcached('wcf_memcached'); + } + else { + $this->memcached = new \Memcached(); + } + + // add servers + $tmp = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHED_HOST)); + $servers = array(); + $defaultWeight = floor(100 / count($tmp)); + foreach ($tmp as $server) { + $server = StringUtil::trim($server); + if (!empty($server)) { + $host = $server; + $port = 11211; // default memcached port + $weight = $defaultWeight; + + // get port + if (strpos($host, ':')) { + $parsedHost = explode(':', $host); + $host = $parsedHost[0]; + $port = $parsedHost[1]; + + if (isset($parsedHost[2])) { + $weight = $parsedHost[2]; + } + } + + $servers[] = array($host, $port, $weight); + } + } + + $this->memcached->addServers($servers); + + // test connection + $this->memcached->get('testing'); + } + + /** + * Returns the memcached object. + * + * @return \Memcached + */ + public function getMemcached() { + return $this->memcached; + } +} diff --git a/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php similarity index 81% rename from wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php rename to wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php index 4397ad73b5..16d7fe19fc 100644 --- a/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php @@ -4,19 +4,19 @@ use wcf\system\WCF; use wcf\util\FileUtil; /** - * MemcacheCacheSource is an implementation of CacheSource that uses a Memcache server to store cached variables. + * MemcachedCacheSource is an implementation of CacheSource that uses a Memcached server to store cached variables. * * @author Marcel Werk - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.cache.source * @category Community Framework */ -class MemcacheCacheSource implements ICacheSource { +class MemcachedCacheSource implements ICacheSource { /** - * MemcacheAdapter object - * @var wcf\system\cache\source\MemcacheAdapter + * MemcachedAdapter object + * @var wcf\system\cache\source\MemcachedAdapter */ protected $adapter = null; @@ -39,16 +39,16 @@ class MemcacheCacheSource implements ICacheSource { protected $obsoleteLogEntries = array(); /** - * Creates a new MemcacheCacheSource object. + * Creates a new MemcachedCacheSource object. */ public function __construct() { - $this->adapter = MemcacheAdapter::getInstance(); + $this->adapter = MemcachedAdapter::getInstance(); } /** - * Returns the memcache adapter. + * Returns the memcached adapter. * - * @return MemcacheAdapter + * @return \MemcachedAdapter */ public function getAdapter() { return $this->adapter; @@ -126,7 +126,7 @@ class MemcacheCacheSource implements ICacheSource { * @see wcf\system\cache\source\ICacheSource::get() */ public function get(array $cacheResource) { - $value = $this->getAdapter()->getMemcache()->get($cacheResource['file']); + $value = $this->getAdapter()->getMemcached()->get($cacheResource['file']); if ($value === false) return null; return $value; } @@ -135,7 +135,7 @@ class MemcacheCacheSource implements ICacheSource { * @see wcf\system\cache\source\ICacheSource::set() */ public function set(array $cacheResource, $value) { - $this->getAdapter()->getMemcache()->set($cacheResource['file'], $value, MEMCACHE_COMPRESSED, $cacheResource['maxLifetime']); + $this->getAdapter()->getMemcached()->set($cacheResource['file'], $value, MEMCACHE_COMPRESSED, $cacheResource['maxLifetime']); $this->addToLog($cacheResource['file']); } @@ -143,7 +143,7 @@ class MemcacheCacheSource implements ICacheSource { * @see wcf\system\cache\source\ICacheSource::delete() */ public function delete(array $cacheResource) { - $this->getAdapter()->getMemcache()->delete($cacheResource['file']); + $this->getAdapter()->getMemcached()->delete($cacheResource['file']); $this->removeFromLog($cacheResource['file']); } @@ -155,7 +155,7 @@ class MemcacheCacheSource implements ICacheSource { $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%').str_replace('*', '.*', str_replace('.', '\.', $filepattern)); foreach ($this->cacheResources as $cacheResource) { if (preg_match('%^'.$pattern.'$%i', $cacheResource)) { - $this->getAdapter()->getMemcache()->delete($cacheResource); + $this->getAdapter()->getMemcached()->delete($cacheResource); $this->removeFromLog($cacheResource); } } @@ -166,7 +166,7 @@ class MemcacheCacheSource implements ICacheSource { */ public function flush() { // clear cache - $this->getAdapter()->getMemcache()->flush(); + $this->getAdapter()->getMemcached()->flush(); // clear log $this->newLogEntries = $this->obsoleteLogEntries = array(); @@ -184,6 +184,6 @@ class MemcacheCacheSource implements ICacheSource { $this->updateLog(); // close connection - if ($this->getAdapter() !== null && $this->getAdapter()->getMemcache() !== null) $this->getAdapter()->getMemcache()->close(); + if ($this->getAdapter() !== null && $this->getAdapter()->getMemcached() !== null) $this->getAdapter()->getMemcached()->close(); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index aa3960936a..49dfadc4b9 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -275,21 +275,21 @@ - - - + + + - + - - memcached.org.]]> + + memcached.org.]]> -- 2.20.1