Removed the min lifetime for cache resources
authorMarcel Werk <burntime@woltlab.com>
Wed, 27 Jul 2011 13:56:06 +0000 (15:56 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 27 Jul 2011 13:56:06 +0000 (15:56 +0200)
Fixed some windows issues

wcfsetup/install/files/lib/data/option/OptionEditor.class.php
wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/cache/CacheHandler.class.php
wcfsetup/install/files/lib/system/cache/SetupCacheHandler.class.php [deleted file]
wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php
wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php
wcfsetup/install/files/lib/system/cache/source/ICacheSource.class.php
wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php
wcfsetup/install/files/lib/util/DirectoryUtil.class.php

index 717fec540320f76616c5bb7a403cd69f521d442c..cc747e555dc2dba789d30dbe29339334b37654e2 100644 (file)
@@ -83,7 +83,7 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject
         */
        public static function resetCache() {
                // reset cache
-               CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.option-*.php', true);
+               CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.option-*.php');
                
                // reset options.inc.php files
                $sql = "SELECT  package, packageID, packageDir
index 92eb8944aa622979f25d14ba581629ed74594319..f1c99433ecb2e68e9550dbd3674c2e1a7006adbe 100644 (file)
@@ -205,7 +205,7 @@ class UserGroupEditor extends DatabaseObjectEditor implements IEditableCachedObj
         */
        public static function resetCache() {
                // clear cache
-               CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.groups*.php', true);
+               CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.groups*.php');
                
                // clear sessions
                SessionHandler::resetSessions();
index 719bffd89b9d120f4571619b192082720ac0b6b3..a7c190f5428e8146b621fa160e4f7db9da02cde3 100644 (file)
@@ -297,12 +297,9 @@ class WCF {
         * Loads the default cache resources.
         */
        protected function loadDefaultCacheResources() {
-               CacheHandler::getInstance()->addResource('languages', WCF_DIR.'cache/cache.languages.php', 'wcf\system\cache\CacheBuilderLanguage');
-               CacheHandler::getInstance()->addResource('spiders', WCF_DIR.'cache/cache.spiders.php', 'wcf\system\cache\CacheBuilderSpider');
                CacheHandler::getInstance()->addResource('languages', WCF_DIR.'cache/cache.languages.php', 'wcf\system\cache\builder\CacheBuilderLanguage');
                CacheHandler::getInstance()->addResource('spiders', WCF_DIR.'cache/cache.spiders.php', 'wcf\system\cache\builder\CacheBuilderSpider');
                if (defined('PACKAGE_ID')) {
-                       CacheHandler::getInstance()->addResource('coreObjects-'.PACKAGE_ID, WCF_DIR.'cache/cache.coreObjects-'.PACKAGE_ID.'.php', 'wcf\system\cache\CacheBuilderCoreObject');
                        CacheHandler::getInstance()->addResource('coreObjects-'.PACKAGE_ID, WCF_DIR.'cache/cache.coreObjects-'.PACKAGE_ID.'.php', 'wcf\system\cache\builder\CacheBuilderCoreObject');
                }
        }
index 7e1d47260e7a672333e23fde1403894a6d420576..e9235979e50f1bc4e7602745c67e5eff55dcf61f 100644 (file)
@@ -55,15 +55,13 @@ class CacheHandler extends SingletonFactory {
         * @param       string          $cache          name of this resource
         * @param       string          $file           data file for this resource
         * @param       string          $className
-        * @param       integer         $minLifetime
         * @param       integer         $maxLifetime
         */
-       public function addResource($cache, $file, $className, $minLifetime = 0, $maxLifetime = 0) {
+       public function addResource($cache, $file, $className, $maxLifetime = 0) {
                $this->cacheResources[$cache] = array(
                        'cache' => $cache,
                        'file' => $file, 
                        'className' => $className, 
-                       'minLifetime' => $minLifetime,
                        'maxLifetime' => $maxLifetime
                );
        }
@@ -72,14 +70,13 @@ class CacheHandler extends SingletonFactory {
         * Deletes a registered cache resource.
         * 
         * @param       string          $cache
-        * @param       boolean         $ignoreLifetime
         */
-       public function clearResource($cache, $ignoreLifetime = false) {
+       public function clearResource($cache) {
                if (!isset($this->cacheResources[$cache])) {
                        throw new SystemException("cache resource '".$cache."' does not exist", 11005);
                }
                
-               $this->getCacheSource()->delete($this->cacheResources[$cache], $ignoreLifetime);
+               $this->getCacheSource()->delete($this->cacheResources[$cache]);
        }
        
        /**
@@ -87,10 +84,9 @@ class CacheHandler extends SingletonFactory {
         *
         * @param       string          $directory
         * @param       string          $filepattern
-        * @param       boolean         $forceDelete
         */
-       public function clear($directory, $filepattern, $forceDelete = false) {
-               $this->getCacheSource()->clear($directory, $filepattern, $forceDelete);
+       public function clear($directory, $filepattern) {
+               $this->getCacheSource()->clear($directory, $filepattern);
        }
        
        /**
diff --git a/wcfsetup/install/files/lib/system/cache/SetupCacheHandler.class.php b/wcfsetup/install/files/lib/system/cache/SetupCacheHandler.class.php
deleted file mode 100644 (file)
index 9592028..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-namespace wcf\system\cache;
-
-/**
- * Disables cache functions during the wcf setup.
- * 
- * @author     Marcel Werk
- * @copyright  2001-2011 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.cache
- * @category   Community Framework
- */
-class SetupCacheHandler extends CacheHandler {
-       /**
-        * @see CacheHandler::addResource()
-        */
-       public function addResource($cache, $file, $classFile, $minLifetime = 0, $maxLifetime = 0) {
-               return false;
-       }
-       
-       /**
-        * @see CacheHandler::clearResource()
-        */
-       public function clearResource($cache, $ignoreLifetime = false) {
-               return false;
-       }
-       
-       /**
-        * @see CacheHandler::clear()
-        */
-       public function clear($directory, $filepattern, $forceDelete = false) {
-               return false;
-       }
-       
-       /**
-        * @see CacheHandler::get()
-        */
-       public function get($cache, $variable = '') {
-               return false;
-       }
-       
-       /**
-        * @see CacheHandler::load()
-        */
-       public function load($cacheResource, $reload = false) {
-               return false;
-       }
-       
-       /**
-        * @see CacheHandler::rebuild()
-        */
-       public function rebuild($cacheResource, $forceRebuilt = false) {
-               return false;
-       }
-}
index bbd79c5f9070fc0f6af22708a28b9cb9d941640a..b3f933d3d35edaed9f1fb29ed61f4810a9774d5b 100644 (file)
@@ -44,34 +44,14 @@ class ApcCacheSource implements ICacheSource {
        /**
         * @see wcf\system\cache\source\ICacheSource::delete()
         */
-       public function delete(array $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(array $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;
+       public function delete(array $cacheResource) {
+               apc_delete($cacheResource['file']);
        }
        
        /**
         * @see wcf\system\cache\source\ICacheSource::clear()
         */
-       public function clear($directory, $filepattern, $forceDelete = false) {
+       public function clear($directory, $filepattern) {
                $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%').str_replace('*', '.*', str_replace('.', '\.', $filepattern));
                
                $apcinfo = apc_cache_info('user');
index ee305614452f41626c465e7777080824a32dfd68..73a840bda4a88fa31c35ff2334e57316315558e1 100644 (file)
@@ -42,7 +42,9 @@ class DiskCacheSource implements ICacheSource {
                        }
                        
                        // load resource
-                       $this->load($cacheResource);
+                       if (!$this->load($cacheResource)) {
+                               return null;
+                       }
                        
                        if (!isset($this->cache[$cacheResource['cache']])) {
                                return null;
@@ -70,15 +72,18 @@ class DiskCacheSource implements ICacheSource {
        /**
         * @see wcf\system\cache\source\ICacheSource::delete()
         */
-       public function delete(array$cacheResource, $ignoreLifetime = false) {
+       public function delete(array $cacheResource) {
                if (file_exists($cacheResource['file'])) {
-                       if ($ignoreLifetime || ($cacheResource['minLifetime'] == 0 || (TIME_NOW - filemtime($cacheResource['file'])) >= $cacheResource['minLifetime'])) {
-                               // delete cache file
+                       if (!@touch($cacheResource['file'], 1)) {
                                @unlink($cacheResource['file']);
+                       }
                                
-                               // reset open cache
-                               if (isset($this->cache[$cacheResource['cache']])) unset($this->cache[$cacheResource['cache']]);
-                               if (isset($this->loaded[$cacheResource['file']])) unset($this->loaded[$cacheResource['file']]);
+                       // reset open cache
+                       if (isset($this->cache[$cacheResource['cache']])) {
+                               unset($this->cache[$cacheResource['cache']]);
+                       }
+                       if (isset($this->loaded[$cacheResource['file']])) {
+                               unset($this->loaded[$cacheResource['file']]);   
                        }
                }
        }
@@ -86,14 +91,18 @@ class DiskCacheSource implements ICacheSource {
        /**
         * @see wcf\system\cache\source\ICacheSource::clear()
         */
-       public function clear($directory, $filepattern, $forceDelete = false) {
+       public function clear($directory, $filepattern) {
+               // unify parameters
+               $directory = FileUtil::unifyDirSeperator($directory);
+               $filepattern = FileUtil::unifyDirSeperator($filepattern);
+               
                $filepattern = str_replace('*', '.*', str_replace('.', '\.', $filepattern));
                if (substr($directory, -1) != '/') {
                        $directory .= '/';      
                }
 
-               DirectoryUtil::getInstance($directory)->executeCallback(function ($filename) use ($forceDelete) {
-                       if ($forceDelete || !@touch($filename, 1)) {
+               DirectoryUtil::getInstance($directory)->executeCallback(function ($filename) {
+                       if (!@touch($filename, 1)) {
                                @unlink($filename);
                        }
                }, '%^'.$directory.$filepattern.'$%i');
@@ -121,11 +130,6 @@ class DiskCacheSource implements ICacheSource {
                        return true;    
                }
                
-               // cache resource has a delay marking
-               if ($cacheResource['minLifetime'] > 0 && (TIME_NOW - $mtime) < $cacheResource['minLifetime']) {
-                       return false;
-               }
-               
                // maxlifetime expired
                if ($cacheResource['maxLifetime'] > 0 && (TIME_NOW - $mtime) > $cacheResource['maxLifetime']) {
                        return true;    
index fcb33fd0a39d4dafbd40b39777ad074021580d64..49f60e08fad1036e687676b81ec2c0e388b6886a 100644 (file)
@@ -32,18 +32,16 @@ interface ICacheSource {
         * Deletes a variable in the cache.
         *
         * @param       array           $cacheResource
-        * @param       boolean         $ignoreLifetime
         */
-       public function delete(array $cacheResource, $ignoreLifetime = false);
+       public function delete(array $cacheResource);
        
        /**
         * Marks cached files as obsolete.
         *
         * @param       string          $directory
         * @param       string          $filepattern
-        * @param       boolean         $forceDelete
         */
-       public function clear($directory, $filepattern, $forceDelete = false);
+       public function clear($directory, $filepattern);
        
        /**
         * Closes this cache source.
index 2ec726b63444f24b05a8beef35670ebf1bcb6a0b..ac8c4fc073b7e575bd97d2addcbc56383d6fadd0 100644 (file)
@@ -145,7 +145,7 @@ class MemcacheCacheSource implements ICacheSource {
        /**
         * @see wcf\system\cache\source\ICacheSource::delete()
         */
-       public function delete(array $cacheResource, $ignoreLifetime = false) {
+       public function delete(array $cacheResource) {
                $this->getAdapter()->getMemcache()->delete($cacheResource['file']);
                $this->removeFromLog($cacheResource['file']);
        }
@@ -153,7 +153,7 @@ class MemcacheCacheSource implements ICacheSource {
        /**
         * @see wcf\system\cache\source\ICacheSource::clear()
         */
-       public function clear($directory, $filepattern, $forceDelete = false) {
+       public function clear($directory, $filepattern) {
                $this->loadLog();
                $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%').str_replace('*', '.*', str_replace('.', '\.', $filepattern));
                foreach ($this->cacheResources as $cacheResource) {
index 1b5c427bfe538cac40ffc9a996137d8b067ce682..f8043ae9987a28a4c40bbc32b5cd2639c2053e24 100644 (file)
@@ -152,7 +152,7 @@ class DirectoryUtil {
                // sort out non matching files
                if (!empty($pattern)) {
                        foreach ($files as $filename => $value) {
-                               if (((bool) preg_match($pattern, $filename)) == $negativeMatch) unset($files[$filename]);
+                               if (((bool) preg_match($pattern, FileUtil::unifyDirSeperator($filename))) == $negativeMatch) unset($files[$filename]);
                        }
                }
 
@@ -188,7 +188,7 @@ class DirectoryUtil {
                // sort out non matching files
                if (!empty($pattern)) {
                        foreach ($objects as $filename => $value) {
-                               if (((bool) preg_match($pattern, $filename)) == $negativeMatch) unset($objects[$filename]);
+                               if (((bool) preg_match($pattern, FileUtil::unifyDirSeperator($filename))) == $negativeMatch) unset($objects[$filename]);
                        }
                }