예제 #1
0
 /**
  * Removes items from the cache by conditions & garbage collector.
  * @param  array  conditions
  * @return void
  */
 public function clean(array $conds)
 {
     if (!empty($conds[Cache::ALL])) {
         $this->memcache->flush();
     } elseif ($this->journal) {
         foreach ($this->journal->clean($conds) as $entry) {
             $this->memcache->delete($entry, 0);
         }
     }
 }
예제 #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);
			}
		}
	}