From: Marcel Werk Date: Wed, 27 Jul 2011 13:56:06 +0000 (+0200) Subject: Removed the min lifetime for cache resources X-Git-Tag: 2.0.0_Beta_1~1934^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=24cdf5679234db584598ab81265c2d79576ba2ad;p=GitHub%2FWoltLab%2FWCF.git Removed the min lifetime for cache resources Fixed some windows issues --- diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 717fec5403..cc747e555d 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php index 92eb8944aa..f1c99433ec 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroupEditor.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 719bffd89b..a7c190f542 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -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'); } } diff --git a/wcfsetup/install/files/lib/system/cache/CacheHandler.class.php b/wcfsetup/install/files/lib/system/cache/CacheHandler.class.php index 7e1d47260e..e9235979e5 100644 --- a/wcfsetup/install/files/lib/system/cache/CacheHandler.class.php +++ b/wcfsetup/install/files/lib/system/cache/CacheHandler.class.php @@ -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 index 9592028c24..0000000000 --- a/wcfsetup/install/files/lib/system/cache/SetupCacheHandler.class.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @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; - } -} diff --git a/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php index bbd79c5f90..b3f933d3d3 100644 --- a/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php @@ -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'); diff --git a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php index ee30561445..73a840bda4 100644 --- a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/system/cache/source/ICacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/ICacheSource.class.php index fcb33fd0a3..49f60e08fa 100644 --- a/wcfsetup/install/files/lib/system/cache/source/ICacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/ICacheSource.class.php @@ -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. diff --git a/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php index 2ec726b634..ac8c4fc073 100644 --- a/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/MemcacheCacheSource.class.php @@ -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) { diff --git a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php index 1b5c427bfe..f8043ae998 100644 --- a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php +++ b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php @@ -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]); } }