Implemented APC cache source.
authorRouL <roul@codingcorner.info>
Thu, 14 Jul 2011 18:28:51 +0000 (20:28 +0200)
committerRouL <roul@codingcorner.info>
Thu, 14 Jul 2011 18:28:51 +0000 (20:28 +0200)
com.woltlab.wcf/options.xml
wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php [new file with mode: 0644]
wcfsetup/install/lang/de-informal.xml
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index e24eed6179c5ab7f4383543b4793cbddf43105c8..8cee3484777d37621e58d09cae0473baaad9e528 100644 (file)
@@ -301,9 +301,11 @@ debug:mail_debug_logfile_path,!mail_use_f_param,!mail_smtp_host,!mail_smtp_port,
                                <optiontype>radiobuttons</optiontype>\r
                                <defaultvalue><![CDATA[disk]]></defaultvalue>\r
                                <selectoptions><![CDATA[disk:wcf.acp.option.cache_source_type.disk\r
-memcache:wcf.acp.option.cache_source_type.memcache]]></selectoptions>\r
+memcache:wcf.acp.option.cache_source_type.memcache\r
+apc:wcf.acp.option.cache_source_type.apc]]></selectoptions>\r
                                <enableoptions><![CDATA[disk:!cache_source_memcache_host,!cache_source_memcache_use_pconnect,!enable_session_data_cache\r
-memcache:cache_source_memcache_host,cache_source_memcache_use_pconnect,enable_session_data_cache]]></enableoptions>\r
+memcache:cache_source_memcache_host,cache_source_memcache_use_pconnect,enable_session_data_cache\r
+apc:!cache_source_memcache_host,!cache_source_memcache_use_pconnect,!enable_session_data_cache]]></enableoptions>\r
                        </option>\r
                        \r
                        <option name="enable_session_data_cache">\r
diff --git a/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php
new file mode 100644 (file)
index 0000000..adc3bec
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+namespace wcf\system\cache\source;
+use wcf\system\exception\SystemException;
+use wcf\util\FileUtil;
+
+/**
+ * ApcCacheSource is an implementation of CacheSource that uses APC to store cached variables.
+ * 
+ * @author     Markus Bartz
+ * @copyright  2011 Markus Bartz
+ * @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 ApcCacheSource implements CacheSource {
+       /**
+        * Creates a new ApcCacheSource object.
+        */
+       public function __construct() {
+               if (!function_exists('apc_exists')) {
+                       throw new SystemException('APC support is not enabled.');
+               }
+       }
+       
+       /**
+        * @see CacheSource::get()
+        */
+       public function get($cacheResource) {
+               if (!apc_exists($cacheResource['file'])) {
+                       return null;
+               }
+               
+               return apc_fetch($cacheResource['file']);
+       }
+       
+       /**
+        * @see CacheSource::set()
+        */
+       public function set($cacheResource, $value) {
+               apc_store($cacheResource['file'], $value, $cacheResource['maxLifetime']);
+       }
+       
+       /**
+        * @see CacheSource::delete()
+        */
+       public function delete($cacheResource, $ignoreLifetime = false) {
+               if ($ignoreLifetime || ($cacheResource['minLifetime'] == 0 || $this->checkMinLifetime($cacheResource))) {
+                       apc_delete($cacheResource['file']);
+               }
+       }
+       
+       /**
+        * Checks if the minimum lifetime is expired.
+        * 
+        * @param       array           $cacheResource
+        */
+       public function checkMinLifetime($cacheResource) {
+               $apcinfo = apc_cache_info('user');
+               $cacheList = $apcinfo['cache_list'];
+               
+               foreach ($cacheList as $cache) {
+                       if ($cache['info'] == $cacheResource['file']) {
+                               return ((TIME_NOW - $cache['mtime']) >= $cacheResource['minLifetime']);
+                       }
+               }
+               
+               return true;
+       }
+       
+       /**
+        * @see CacheSource::clear()
+        */
+       public function clear($directory, $filepattern, $forceDelete = false) {
+               $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%').str_replace('*', '.*', str_replace('.', '\.', $filepattern));
+               
+               $apcinfo = apc_cache_info('user');
+               $cacheList = $apcinfo['cache_list'];
+               foreach ($cacheList as $cache) {
+                       if (preg_match('%^'.$pattern.'$%i', $cache['info'])) {
+                               apc_delete($cache['info']);
+                       }
+               }
+       }
+       
+       /**
+        * @see CacheSource::close()
+        */
+       public function close() {
+               // does nothing
+       }
+       
+       /**
+        * @see CacheSource::flush()
+        */
+       public function flush() {
+               apc_clear_cache('user');
+       }
+}
+?>
index bcac8b75dfe9c8b854b29f2008674651780c0aa0..9452b34bcd8b3b1afbdb755f0227906a3d543557 100644 (file)
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect"><![CDATA[Persistente Verbindungen aktivieren]]></item>\r
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect.description"><![CDATA[Sollen beim Verbinden mit dem Memcache-Server persistente Verbindungen genutzt werden?]]></item>\r
                <item name="wcf.acp.option.cache_source_type"><![CDATA[Cache-Methode]]></item>\r
+               <item name="wcf.acp.option.cache_source_type.apc"><![CDATA[Alternative PHP Cache]]></item>\r
                <item name="wcf.acp.option.cache_source_type.description"><![CDATA[Bitte wähle die gewünschte Cache-Methode aus! Beachte, dass einige Methoden spezielle Anforderungen an das Server-System stellen und nicht auf jedem Server zur Verfügung stehen.]]></item>\r
                <item name="wcf.acp.option.cache_source_type.disk"><![CDATA[Dateisystem (Standard)]]></item>\r
                <item name="wcf.acp.option.cache_source_type.memcache"><![CDATA[Memcache (Experimentell)]]></item>\r
index b2acdba7ddd4a7adb0319e5144523cc8b15b0af8..68e34ccb69f7fd338eacca9b65d592284dc40f1e 100644 (file)
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect"><![CDATA[Persistente Verbindungen aktivieren]]></item>\r
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect.description"><![CDATA[Sollen beim Verbinden mit dem Memcache-Server persistente Verbindungen genutzt werden?]]></item>\r
                <item name="wcf.acp.option.cache_source_type"><![CDATA[Cache-Methode]]></item>\r
+               <item name="wcf.acp.option.cache_source_type.apc"><![CDATA[Alternative PHP Cache]]></item>\r
                <item name="wcf.acp.option.cache_source_type.description"><![CDATA[Bitte wählen Sie die gewünschte Cache-Methode aus! Beachten Sie, dass einige Methoden spezielle Anforderungen an das Server-System stellen und nicht auf jedem Server zur Verfügung stehen.]]></item>\r
                <item name="wcf.acp.option.cache_source_type.disk"><![CDATA[Dateisystem (Standard)]]></item>\r
                <item name="wcf.acp.option.cache_source_type.memcache"><![CDATA[Memcache (Experimentell)]]></item>\r
index a676ad8fb32c5ffd75968eb9674d1b68e2cb5c73..ce5c59e375c58af5148f25d8f943dd73af0a3023 100644 (file)
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect"><![CDATA[Use persistent connections]]></item>\r
                <item name="wcf.acp.option.cache_source_memcache_use_pconnect.description"><![CDATA[By enabling this option a persistent connection to the memcache server will be used.]]></item>\r
                <item name="wcf.acp.option.cache_source_type"><![CDATA[Cache type]]></item>\r
+               <item name="wcf.acp.option.cache_source_type.apc"><![CDATA[Alternative PHP Cache]]></item>\r
                <item name="wcf.acp.option.cache_source_type.description"><![CDATA[Please select the type of cache you want to use. Some of the types have special requirements to the server system and cannot be used in your environment.]]></item>\r
                <item name="wcf.acp.option.cache_source_type.disk"><![CDATA[File system (default)]]></item>\r
                <item name="wcf.acp.option.cache_source_type.memcache"><![CDATA[Memcache (experimental)]]></item>\r