Skip to content

Commit

Permalink
Merge pull request #2 from qantus/feature
Browse files Browse the repository at this point in the history
Added checking existing cache files
  • Loading branch information
Maxim committed Dec 19, 2014
2 parents dc6a7c6 + 5d584be commit 09a6bae
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Mindy/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function init()
public function exists($key)
{
$cacheFile = $this->getCacheFile($this->buildKey($key));
return @filemtime($cacheFile) > time();
return file_exists($cacheFile) && @filemtime($cacheFile) > time();
}

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ protected function setValue($key, $value, $expire)
protected function addValue($key, $value, $expire)
{
$cacheFile = $this->getCacheFile($key);
if (@filemtime($cacheFile) > time()) {
if (file_exists($cacheFile) && @filemtime($cacheFile) > time()) {
return false;
}
return $this->setValue($key, $value, $expire);
Expand All @@ -168,7 +168,10 @@ protected function addValue($key, $value, $expire)
protected function deleteValue($key)
{
$cacheFile = $this->getCacheFile($key);
return @unlink($cacheFile);
if (file_exists($cacheFile)) {
return @unlink($cacheFile);
}
return true;
}

/**
Expand Down Expand Up @@ -237,7 +240,9 @@ protected function gcRecursive($path, $expiredOnly)
@rmdir($fullPath);
}
} elseif (!$expiredOnly || $expiredOnly && @filemtime($fullPath) < time()) {
@unlink($fullPath);
if (file_exists($fullPath)) {
@unlink($fullPath);
}
}
}
closedir($handle);
Expand Down

0 comments on commit 09a6bae

Please sign in to comment.