32 lines
692 B
PHP
32 lines
692 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::rememberForever($this->cacheKey($path, $size), fn () => $this->tag->generate($path, $size));
|
||
|
}
|
||
|
|
||
|
private function cacheKey(string $path, string $size): string
|
||
|
{
|
||
|
$normalPath = $this->fileObserver->normalizePath($path);
|
||
|
|
||
|
return "resize.{$size}.{$normalPath}";
|
||
|
}
|
||
|
|
||
|
}
|