Rename FilesCache::isValid() to FilesCache::hasExpired()

This commit is contained in:
Giuseppe Criscione 2020-12-24 22:42:18 +01:00
parent 9131747153
commit de1dbdc3cf
2 changed files with 9 additions and 6 deletions

View File

@ -42,7 +42,7 @@ class FilesCache extends AbstractCache
$data = PHP::parseFile($this->getFile($key));
return $data['value'];
}
if (!$this->isValid($key)) {
if ($this->hasExpired($key)) {
FileSystem::delete($this->getFile($key));
}
return null;
@ -81,7 +81,7 @@ class FilesCache extends AbstractCache
*/
public function has(string $key): bool
{
return FileSystem::exists($this->getFile($key)) && $this->isValid($key);
return FileSystem::exists($this->getFile($key)) && !$this->hasExpired($key);
}
/**
@ -95,9 +95,9 @@ class FilesCache extends AbstractCache
/**
* Return whether a cached resource has not expired
*/
protected function isValid(string $key): bool
protected function hasExpired(string $key): bool
{
$data = PHP::parseFile($this->getFile($key));
return time() < $data['expires'];
return time() >= $data['expires'];
}
}

View File

@ -10,9 +10,12 @@ class SiteCache extends FilesCache
/**
* @inheritdoc
*/
protected function isValid(string $key): bool
protected function hasExpired(string $key): bool
{
if (parent::hasExpired($key)) {
return true;
}
$lastModified = FileSystem::lastModifiedTime($this->getFile($key));
return parent::isValid($key) && !Formwork::instance()->site()->modifiedSince($lastModified);
return Formwork::instance()->site()->modifiedSince($lastModified);
}
}