* @category Community Framework
*/
class DiskCacheSource implements ICacheSource {
+ /**
+ * up-to-date directory util object for the cache folder
+ * @var wcf\util\DirectoryUtil
+ */
+ protected $directoryUtil = null;
+
/**
* @see wcf\system\cache\source\ICacheSource::flush()
*/
* @see wcf\system\cache\source\ICacheSource::flushAll()
*/
public function flushAll() {
- DirectoryUtil::getInstance(WCF_DIR.'cache/')->removePattern(new Regex('.*\.php$'));
+ $this->getDirectoryUtil()->removePattern(new Regex('.*\.php$'));
}
/**
$file->write("<?php exit; /* cache: ".$cacheName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
$file->write(serialize($value));
$file->close();
+
+ // unset current DirectoryUtil object to make sure new cache file
+ // can be deleted in the same request
+ $this->directoryUtil = null;
}
/**
$directory = FileUtil::unifyDirSeperator(WCF_DIR.'cache/');
$pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern));
- DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) {
+ $this->getDirectoryUtil()->executeCallback(new Callback(function ($filename) {
if (!@touch($filename, 1)) {
@unlink($filename);
}
return $value;
}
+
+ /**
+ * Returns an up-to-date directory util object for the cache folder.
+ *
+ * @return wcf\util\DirectoryUtil
+ */
+ protected function getDirectoryUtil() {
+ if ($this->directoryUtil === null) {
+ $this->directoryUtil = new DirectoryUtil(WCF_DIR.'cache/');
+ }
+
+ return $this->directoryUtil;
+ }
}
false => array() // non-recursive instances
);
+ /**
+ * Creates a new instance of DirectoryUtil.
+ *
+ * @param string $directory directory path
+ * @param boolean $recursive created a recursive directory iterator
+ * @see wcf\util\DirectoryUtil::getInstance()
+ */
+ public function __construct($directory, $recursive = true) {
+ $this->directory = $directory;
+ $this->recursive = $recursive;
+
+ // handle iterator type
+ if ($this->recursive) {
+ $this->obj = new \RecursiveDirectoryIterator($directory);
+ }
+ else {
+ $this->obj = new \DirectoryIterator($directory);
+ }
+ }
+
/**
* Returns an instance of DirectoryUtil (or child).
*
return static::$instances[$recursive][$directory];
}
- /**
- * Creates a new instance of DirectoryUtil.
- *
- * @param string $directory directory path
- * @param boolean $recursive created a recursive directory iterator
- * @see wcf\util\DirectoryUtil::getInstance()
- */
- protected function __construct($directory, $recursive = true) {
- $this->directory = $directory;
- $this->recursive = $recursive;
-
- // handle iterator type
- if ($this->recursive) {
- $this->obj = new \RecursiveDirectoryIterator($directory);
- }
- else {
- $this->obj = new \DirectoryIterator($directory);
- }
- }
-
/**
* @see wcf\util\DirectoryUtil::getInstance()
*/