Update Cache\FileCache

Add cache cleaning by condition
This commit is contained in:
Visman 2021-12-31 13:13:18 +07:00
parent be151ee006
commit a23ab87106

View file

@ -28,7 +28,7 @@ class FileCache implements CacheInterface
*/
protected $cacheDir;
public function __construct(string $dir)
public function __construct(string $dir, /* string */ $resetMark)
{
$dir = \rtrim($dir, '\\/');
@ -41,6 +41,10 @@ class FileCache implements CacheInterface
}
$this->cacheDir = $dir;
if (\is_string($resetMark)) {
$this->resetIfRequired($resetMark);
}
}
/**
@ -237,4 +241,21 @@ class FileCache implements CacheInterface
throw new InvalidArgumentException('Expects a iterable, got: ' . \gettype($iterable));
}
}
/**
* Сбрасывает кеш при изменении $resetMark
*/
protected function resetIfRequired(string $resetMark): void
{
if (empty($resetMark)) {
return;
}
$hash = \sha1($resetMark);
if ($this->get('reset_mark_hash') !== $hash) {
$this->clear();
$this->set('reset_mark_hash', $hash);
}
}
}