mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-29 19:37:44 +01:00
Use CacheItem
in FilesCache
This commit is contained in:
parent
b7d7e29f13
commit
6cdd584694
@ -35,8 +35,8 @@ class FilesCache extends AbstractCache
|
||||
public function fetch(string $key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
$data = PHP::parseFile($this->getFile($key));
|
||||
return $data['value'];
|
||||
$cacheItem = CacheItem::fromArray(PHP::parseFile($this->getFile($key)));
|
||||
return $cacheItem->value();
|
||||
}
|
||||
if ($this->hasExpired($key)) {
|
||||
FileSystem::delete($this->getFile($key));
|
||||
@ -49,8 +49,8 @@ class FilesCache extends AbstractCache
|
||||
*/
|
||||
public function save(string $key, $value, int $ttl = null): void
|
||||
{
|
||||
$data = ['value' => $value, 'expires' => time() + ($ttl ?? $this->defaultTtl)];
|
||||
PHP::encodeToFile($data, $this->getFile($key));
|
||||
$cacheItem = new CacheItem($value, time() + ($ttl ?? $this->defaultTtl), time());
|
||||
PHP::encodeToFile($cacheItem->toArray(), $this->getFile($key));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ class FilesCache extends AbstractCache
|
||||
*/
|
||||
protected function hasExpired(string $key): bool
|
||||
{
|
||||
$data = PHP::parseFile($this->getFile($key));
|
||||
return time() >= $data['expires'];
|
||||
$cacheItem = CacheItem::fromArray(PHP::parseFile($this->getFile($key)));
|
||||
return time() >= $cacheItem->expirationTime();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user