oc-resizer-plugin/classes/CacheManager.php

32 lines
692 B
PHP
Raw Normal View History

2021-09-06 14:37:35 +02:00
<?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}";
}
}