<category name="general.cache.general">
<parent>general.cache</parent>
</category>
- <category name="general.cache.memcache">
+ <category name="general.cache.memcached">
<parent>general.cache</parent>
</category>
<!-- /general -->
<optiontype>radioButton</optiontype>
<defaultvalue><![CDATA[disk]]></defaultvalue>
<selectoptions><![CDATA[disk:wcf.acp.option.cache_source_type.disk
-memcache:wcf.acp.option.cache_source_type.memcache
+memcached:wcf.acp.option.cache_source_type.memcached
apc:wcf.acp.option.cache_source_type.apc
no:wcf.acp.option.cache_source_type.no]]></selectoptions>
- <enableoptions><![CDATA[disk:!cache_source_memcache_host,!cache_source_memcache_use_pconnect
-memcache:cache_source_memcache_host,cache_source_memcache_use_pconnect
-apc:!cache_source_memcache_host,!cache_source_memcache_use_pconnect
-no:!cache_source_memcache_host,!cache_source_memcache_use_pconnect]]></enableoptions>
+ <enableoptions><![CDATA[disk:!cache_source_memcached_host,!cache_source_memcached_use_pconnect
+memcached:cache_source_memcached_host,cache_source_memcached_use_pconnect
+apc:!cache_source_memcached_host,!cache_source_memcached_use_pconnect
+no:!cache_source_memcached_host,!cache_source_memcached_use_pconnect]]></enableoptions>
</option>
- <option name="cache_source_memcache_host">
- <categoryname>general.cache.memcache</categoryname>
+ <option name="cache_source_memcached_host">
+ <categoryname>general.cache.memcached</categoryname>
<optiontype>textarea</optiontype>
</option>
- <option name="cache_source_memcache_use_pconnect">
- <categoryname>general.cache.memcache</categoryname>
+ <option name="cache_source_memcached_use_pconnect">
+ <categoryname>general.cache.memcached</categoryname>
<optiontype>boolean</optiontype>
</option>
<!-- /general.cache -->
}
break;
- case 'wcf\system\cache\source\MemcacheCacheSource':
+ case 'wcf\system\cache\source\MemcachedCacheSource':
// set version
$this->cacheData['version'] = WCF_VERSION;
+++ /dev/null
-<?php
-namespace wcf\system\cache\source;
-use wcf\system\exception\SystemException;
-use wcf\system\SingletonFactory;
-use wcf\util\StringUtil;
-
-/**
- * Provides a global adapter for accessing the memcache server.
- *
- * @author Marcel Werk
- * @copyright 2001-2012 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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;
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\cache\source;
-use wcf\system\WCF;
-use wcf\util\FileUtil;
-
-/**
- * MemcacheCacheSource is an implementation of CacheSource that uses a Memcache server to store cached variables.
- *
- * @author Marcel Werk
- * @copyright 2001-2012 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.cache.source
- * @category Community Framework
- */
-class MemcacheCacheSource implements ICacheSource {
- /**
- * MemcacheAdapter object
- * @var wcf\system\cache\source\MemcacheAdapter
- */
- protected $adapter = null;
-
- /**
- * list of cache resources
- * @var array<string>
- */
- protected $cacheResources = null;
-
- /**
- * list of new cache resources
- * @var array<string>
- */
- protected $newLogEntries = array();
-
- /**
- * list of obsolete resources
- * @var array<string>
- */
- protected $obsoleteLogEntries = array();
-
- /**
- * Creates a new MemcacheCacheSource object.
- */
- public function __construct() {
- $this->adapter = MemcacheAdapter::getInstance();
- }
-
- /**
- * Returns the memcache adapter.
- *
- * @return MemcacheAdapter
- */
- public function getAdapter() {
- return $this->adapter;
- }
-
- // internal log functions
- /**
- * Loads the cache log.
- */
- protected function loadLog() {
- if ($this->cacheResources === null) {
- $this->cacheResources = array();
- $sql = "SELECT *
- FROM wcf".WCF_N."_cache_resource";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- while ($row = $statement->fetchArray()) {
- $this->cacheResources[] = $row['cacheResource'];
- }
- }
- }
-
- /**
- * Saves modifications of the cache log.
- */
- protected function updateLog() {
- if (!empty($this->newLogEntries)) {
- $sql = "DELETE FROM wcf".WCF_N."_cache_resource
- WHERE cacheResource = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- foreach ($this->newLogEntries as $entry) {
- $statement->execute(array($entry));
- }
-
- $sql = "INSERT INTO wcf".WCF_N."_cache_resource
- (cacheResource)
- VALUES (?)";
- $statement = WCF::getDB()->prepareStatement($sql);
- foreach ($this->newLogEntries as $entry) {
- $statement->execute(array($entry));
- }
-
- }
-
- if (!empty($this->obsoleteLogEntries)) {
- $sql = "DELETE FROM wcf".WCF_N."_cache_resource
- WHERE cacheResource = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- foreach ($this->obsoleteLogEntries as $entry) {
- $statement->execute(array($entry));
- }
- }
- }
-
- /**
- * Adds a cache resource to cache log.
- *
- * @param string $cacheResource
- */
- protected function addToLog($cacheResource) {
- $this->newLogEntries[] = $cacheResource;
- }
-
- /**
- * Removes an obsolete cache resource from cache log.
- *
- * @param string $cacheResource
- */
- protected function removeFromLog($cacheResource) {
- $this->obsoleteLogEntries[] = $cacheResource;
- }
-
- // CacheSource implementations
- /**
- * @see wcf\system\cache\source\ICacheSource::get()
- */
- public function get(array $cacheResource) {
- $value = $this->getAdapter()->getMemcache()->get($cacheResource['file']);
- if ($value === false) return null;
- return $value;
- }
-
- /**
- * @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->addToLog($cacheResource['file']);
- }
-
- /**
- * @see wcf\system\cache\source\ICacheSource::delete()
- */
- public function delete(array $cacheResource) {
- $this->getAdapter()->getMemcache()->delete($cacheResource['file']);
- $this->removeFromLog($cacheResource['file']);
- }
-
- /**
- * @see wcf\system\cache\source\ICacheSource::clear()
- */
- public function clear($directory, $filepattern) {
- $this->loadLog();
- $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->removeFromLog($cacheResource);
- }
- }
- }
-
- /**
- * @see wcf\system\cache\source\ICacheSource::flush()
- */
- public function flush() {
- // clear cache
- $this->getAdapter()->getMemcache()->flush();
-
- // clear log
- $this->newLogEntries = $this->obsoleteLogEntries = array();
-
- $sql = "DELETE FROM wcf".WCF_N."_cache_resource";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- }
-
- /**
- * @see wcf\system\cache\source\ICacheSource::close()
- */
- public function close() {
- // update log
- $this->updateLog();
-
- // close connection
- if ($this->getAdapter() !== null && $this->getAdapter()->getMemcache() !== null) $this->getAdapter()->getMemcache()->close();
- }
-}
--- /dev/null
+<?php
+namespace wcf\system\cache\source;
+use wcf\system\exception\SystemException;
+use wcf\system\SingletonFactory;
+use wcf\util\StringUtil;
+
+/**
+ * Provides a global adapter for accessing the memcached server.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2013 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\cache\source;
+use wcf\system\WCF;
+use wcf\util\FileUtil;
+
+/**
+ * MemcachedCacheSource is an implementation of CacheSource that uses a Memcached server to store cached variables.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2013 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cache.source
+ * @category Community Framework
+ */
+class MemcachedCacheSource implements ICacheSource {
+ /**
+ * MemcachedAdapter object
+ * @var wcf\system\cache\source\MemcachedAdapter
+ */
+ protected $adapter = null;
+
+ /**
+ * list of cache resources
+ * @var array<string>
+ */
+ protected $cacheResources = null;
+
+ /**
+ * list of new cache resources
+ * @var array<string>
+ */
+ protected $newLogEntries = array();
+
+ /**
+ * list of obsolete resources
+ * @var array<string>
+ */
+ protected $obsoleteLogEntries = array();
+
+ /**
+ * Creates a new MemcachedCacheSource object.
+ */
+ public function __construct() {
+ $this->adapter = MemcachedAdapter::getInstance();
+ }
+
+ /**
+ * Returns the memcached adapter.
+ *
+ * @return \MemcachedAdapter
+ */
+ public function getAdapter() {
+ return $this->adapter;
+ }
+
+ // internal log functions
+ /**
+ * Loads the cache log.
+ */
+ protected function loadLog() {
+ if ($this->cacheResources === null) {
+ $this->cacheResources = array();
+ $sql = "SELECT *
+ FROM wcf".WCF_N."_cache_resource";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute();
+ while ($row = $statement->fetchArray()) {
+ $this->cacheResources[] = $row['cacheResource'];
+ }
+ }
+ }
+
+ /**
+ * Saves modifications of the cache log.
+ */
+ protected function updateLog() {
+ if (!empty($this->newLogEntries)) {
+ $sql = "DELETE FROM wcf".WCF_N."_cache_resource
+ WHERE cacheResource = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($this->newLogEntries as $entry) {
+ $statement->execute(array($entry));
+ }
+
+ $sql = "INSERT INTO wcf".WCF_N."_cache_resource
+ (cacheResource)
+ VALUES (?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($this->newLogEntries as $entry) {
+ $statement->execute(array($entry));
+ }
+
+ }
+
+ if (!empty($this->obsoleteLogEntries)) {
+ $sql = "DELETE FROM wcf".WCF_N."_cache_resource
+ WHERE cacheResource = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($this->obsoleteLogEntries as $entry) {
+ $statement->execute(array($entry));
+ }
+ }
+ }
+
+ /**
+ * Adds a cache resource to cache log.
+ *
+ * @param string $cacheResource
+ */
+ protected function addToLog($cacheResource) {
+ $this->newLogEntries[] = $cacheResource;
+ }
+
+ /**
+ * Removes an obsolete cache resource from cache log.
+ *
+ * @param string $cacheResource
+ */
+ protected function removeFromLog($cacheResource) {
+ $this->obsoleteLogEntries[] = $cacheResource;
+ }
+
+ // CacheSource implementations
+ /**
+ * @see wcf\system\cache\source\ICacheSource::get()
+ */
+ public function get(array $cacheResource) {
+ $value = $this->getAdapter()->getMemcached()->get($cacheResource['file']);
+ if ($value === false) return null;
+ return $value;
+ }
+
+ /**
+ * @see wcf\system\cache\source\ICacheSource::set()
+ */
+ public function set(array $cacheResource, $value) {
+ $this->getAdapter()->getMemcached()->set($cacheResource['file'], $value, MEMCACHE_COMPRESSED, $cacheResource['maxLifetime']);
+ $this->addToLog($cacheResource['file']);
+ }
+
+ /**
+ * @see wcf\system\cache\source\ICacheSource::delete()
+ */
+ public function delete(array $cacheResource) {
+ $this->getAdapter()->getMemcached()->delete($cacheResource['file']);
+ $this->removeFromLog($cacheResource['file']);
+ }
+
+ /**
+ * @see wcf\system\cache\source\ICacheSource::clear()
+ */
+ public function clear($directory, $filepattern) {
+ $this->loadLog();
+ $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%').str_replace('*', '.*', str_replace('.', '\.', $filepattern));
+ foreach ($this->cacheResources as $cacheResource) {
+ if (preg_match('%^'.$pattern.'$%i', $cacheResource)) {
+ $this->getAdapter()->getMemcached()->delete($cacheResource);
+ $this->removeFromLog($cacheResource);
+ }
+ }
+ }
+
+ /**
+ * @see wcf\system\cache\source\ICacheSource::flush()
+ */
+ public function flush() {
+ // clear cache
+ $this->getAdapter()->getMemcached()->flush();
+
+ // clear log
+ $this->newLogEntries = $this->obsoleteLogEntries = array();
+
+ $sql = "DELETE FROM wcf".WCF_N."_cache_resource";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute();
+ }
+
+ /**
+ * @see wcf\system\cache\source\ICacheSource::close()
+ */
+ public function close() {
+ // update log
+ $this->updateLog();
+
+ // close connection
+ if ($this->getAdapter() !== null && $this->getAdapter()->getMemcached() !== null) $this->getAdapter()->getMemcached()->close();
+ }
+}
<item name="wcf.acp.option.blacklist_ip_addresses.description"><![CDATA[Eine Adresse pro Zeile]]></item>
<item name="wcf.acp.option.blacklist_user_agents"><![CDATA[Browser-Kennung ausschließen]]></item>
<item name="wcf.acp.option.blacklist_user_agents.description"><![CDATA[Eine Browser-Kennung (User-Agent) pro Zeile]]></item>
- <item name="wcf.acp.option.cache_source_memcache_host"><![CDATA[Memcache-Server]]></item>
- <item name="wcf.acp.option.cache_source_memcache_host.description"><![CDATA[Mehrere Server können zeilenweise angegeben werden.]]></item>
- <item name="wcf.acp.option.cache_source_memcache_use_pconnect"><![CDATA[Persistente Verbindungen aktivieren]]></item>
+ <item name="wcf.acp.option.cache_source_memcached_host"><![CDATA[Memcached-Server]]></item>
+ <item name="wcf.acp.option.cache_source_memcached_host.description"><![CDATA[Mehrere Server können zeilenweise angegeben werden, die Gewichtung kann als dritter Parameter angegeben werden, zum Beispiel „localhost:11211:67“ oder „10.0.13.37:31337:33“.]]></item>
+ <item name="wcf.acp.option.cache_source_memcached_use_pconnect"><![CDATA[Persistente Verbindungen aktivieren]]></item>
<item name="wcf.acp.option.cache_source_type"><![CDATA[Cache-Methode]]></item>
<item name="wcf.acp.option.cache_source_type.apc"><![CDATA[Alternative PHP Cache (experimentell)]]></item>
<item name="wcf.acp.option.cache_source_type.description"><![CDATA[Beachten Sie, dass einige Methoden spezielle Anforderungen an das Server-System stellen und nicht auf jedem Server zur Verfügung stehen.]]></item>
<item name="wcf.acp.option.cache_source_type.disk"><![CDATA[Dateisystem (Standard)]]></item>
- <item name="wcf.acp.option.cache_source_type.memcache"><![CDATA[Memcache]]></item>
+ <item name="wcf.acp.option.cache_source_type.memcached"><![CDATA[Memcached]]></item>
<item name="wcf.acp.option.cache_source_type.no"><![CDATA[Caching deaktivieren (Nicht empfohlen)]]></item>
<item name="wcf.acp.option.category.general"><![CDATA[Allgemein]]></item>
<item name="wcf.acp.option.category.general.cache"><![CDATA[Cache]]></item>
<item name="wcf.acp.option.category.general.cache.general"><![CDATA[Allgemein]]></item>
- <item name="wcf.acp.option.category.general.cache.memcache"><![CDATA[Memcache]]></item>
- <item name="wcf.acp.option.category.general.cache.memcache.description"><![CDATA[Memcache speichert häufig benötige Daten im Arbeitsspeicher zwischen. Dies kann die Last auf die Datenbank und das Dateisystem drastisch reduzieren. Lesen Sie mehr über dieses Thema auf der folgenden Seite: <a href="http://memcached.org/" class="externalURL">memcached.org</a>.]]></item>
+ <item name="wcf.acp.option.category.general.cache.memcached"><![CDATA[Memcached]]></item>
+ <item name="wcf.acp.option.category.general.cache.memcached.description"><![CDATA[Memcached speichert häufig benötige Daten im Arbeitsspeicher zwischen. Dies kann die Last auf die Datenbank und das Dateisystem drastisch reduzieren. Lesen Sie mehr über dieses Thema auf der folgenden Seite: <a href="http://memcached.org/" class="externalURL">memcached.org</a>.]]></item>
<item name="wcf.acp.option.category.general.system.date"><![CDATA[Datum & Zeit]]></item>
<item name="wcf.acp.option.category.general.system.image"><![CDATA[Grafik]]></item>
<item name="wcf.acp.option.category.general.system"><![CDATA[System]]></item>