49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Aweos\Resizer\Classes;
|
|
|
|
use Cache;
|
|
|
|
class CacheManager
|
|
{
|
|
|
|
public FileObserver $fileObserver;
|
|
public TagGenerator $tag;
|
|
|
|
public function __construct(FileObserver $fileObserver, TagGenerator $tag)
|
|
{
|
|
$this->tag = $tag;
|
|
$this->fileObserver = $fileObserver;
|
|
}
|
|
|
|
public function get(string $path, string $size, ?string $sizes): string
|
|
{
|
|
return Cache::tags($this->getTag($path, $sizes))
|
|
->rememberForever($this->cacheKey($path, $size), fn () => $this->tag->generate($path, $size, $sizes));
|
|
}
|
|
|
|
public function delete(string $path): void
|
|
{
|
|
$path = $this->fileObserver->normalizePath($path);
|
|
Cache::tags("resizer.$path")->flush();
|
|
}
|
|
|
|
private function getTag(string $path): array
|
|
{
|
|
return ['resizer', "resizer.{$this->fileObserver->normalizePath($path)}"];
|
|
}
|
|
|
|
private function cacheKey(string $path, string $size): string
|
|
{
|
|
$normalPath = $this->fileObserver->normalizePath($path);
|
|
|
|
return "resizer.{$size}.{$normalPath}";
|
|
}
|
|
|
|
public function flush(): void
|
|
{
|
|
Cache::tags('resizer')->flush();
|
|
}
|
|
|
|
}
|