From de1dbdc3cf32174cb0df5db5343712f6f8598af7 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Thu, 24 Dec 2020 22:42:18 +0100 Subject: [PATCH] Rename `FilesCache::isValid()` to `FilesCache::hasExpired()` --- formwork/src/Cache/FilesCache.php | 8 ++++---- formwork/src/Cache/SiteCache.php | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/formwork/src/Cache/FilesCache.php b/formwork/src/Cache/FilesCache.php index daf5a5cf..8c3100fc 100644 --- a/formwork/src/Cache/FilesCache.php +++ b/formwork/src/Cache/FilesCache.php @@ -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']; } } diff --git a/formwork/src/Cache/SiteCache.php b/formwork/src/Cache/SiteCache.php index a817e276..fb6c3487 100644 --- a/formwork/src/Cache/SiteCache.php +++ b/formwork/src/Cache/SiteCache.php @@ -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); } }