コード例 #1
0
ファイル: nette.php プロジェクト: kacer/FakturoidPairing
 function clean(array $conds)
 {
     $all = !empty($conds[NCache::ALL]);
     $collector = empty($conds);
     if ($all || $collector) {
         $now = time();
         foreach (NFinder::find('*')->from($this->dir)->childFirst() as $entry) {
             $path = (string) $entry;
             if ($entry->isDir()) {
                 @rmdir($path);
                 continue;
             }
             if ($all) {
                 $this->delete($path);
             } else {
                 $meta = $this->readMeta($path, LOCK_SH);
                 if (!$meta) {
                     continue;
                 }
                 if (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < $now) {
                     $this->delete($path, $meta[self::HANDLE]);
                     continue;
                 }
                 fclose($meta[self::HANDLE]);
             }
         }
         if ($this->context) {
             $this->getJournal()->clean($conds);
         }
         return;
     }
     if ($this->context) {
         foreach ($this->getJournal()->clean($conds) as $file) {
             $this->delete($file);
         }
     }
 }
コード例 #2
0
	/**
	 * Removes items from the cache by conditions & garbage collector.
	 * @param  array  conditions
	 * @return void
	 */
	public function clean(array $conds)
	{
		$all = !empty($conds[NCache::ALL]);
		$collector = empty($conds);

		// cleaning using file iterator
		if ($all || $collector) {
			$now = time();
			foreach (NFinder::find('*')->from($this->dir)->childFirst() as $entry) {
				$path = (string) $entry;
				if ($entry->isDir()) { // collector: remove empty dirs
					@rmdir($path); // @ - removing dirs is not necessary
					continue;
				}
				if ($all) {
					$this->delete($path);

				} else { // collector
					$meta = $this->readMetaAndLock($path, LOCK_SH);
					if (!$meta) {
						continue;
					}

					if ((!empty($meta[self::META_DELTA]) && filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < $now)
						|| (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < $now)
					) {
						$this->delete($path, $meta[self::HANDLE]);
						continue;
					}

					flock($meta[self::HANDLE], LOCK_UN);
					fclose($meta[self::HANDLE]);
				}
			}

			if ($this->journal) {
				$this->journal->clean($conds);
			}
			return;
		}

		// cleaning using journal
		if ($this->journal) {
			foreach ($this->journal->clean($conds) as $file) {
				$this->delete($file);
			}
		}
	}