44 lines
1010 B
PHP
44 lines
1010 B
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
|
|
{
|
|
return Cache::tags($this->getTag($path))
|
|
->rememberForever($this->cacheKey($path, $size), fn () => $this->tag->generate($path, $size));
|
|
}
|
|
|
|
public function delete(string $path): void
|
|
{
|
|
$path = $this->fileObserver->normalizePath($path);
|
|
Cache::tags($path)->flush();
|
|
}
|
|
|
|
private function getTag(string $path): string
|
|
{
|
|
return $this->fileObserver->normalizePath($path);
|
|
}
|
|
|
|
private function cacheKey(string $path, string $size): string
|
|
{
|
|
$normalPath = $this->fileObserver->normalizePath($path);
|
|
|
|
return "resize.{$size}.{$normalPath}";
|
|
}
|
|
|
|
}
|