Update Cache\FileCache
Add cache cleaning by condition
This commit is contained in:
parent
be151ee006
commit
a23ab87106
1 changed files with 22 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue