Skip to content

Commit b24476a

Browse files
committed
feat: Improve cache
1 parent 9df00d9 commit b24476a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Model/Resize.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class Resize
9999
* @var string $absolutePathoriginal
100100
*/
101101
protected $absolutePathoriginal;
102+
/**
103+
* @var array $tempCache
104+
*/
105+
protected $tempCache = [];
102106
/**
103107
* @var array
104108
*
@@ -208,10 +212,15 @@ public function __construct(
208212
*
209213
* @return string
210214
*/
211-
public function resizeAndGetUrl(string $imagePath, $width, $height, array $resizeSettings = [], string $format = null): string
215+
public function resizeAndGetUrl(string $imagePath, $width, $height, array $resizeSettings = [], ?string $format = null): string
212216
{
213-
$cacheKey = md5($imagePath . '-' . $width . '-' . $height . '-' . json_encode($resizeSettings));
217+
$cacheKey = md5($imagePath . '-' . $width . '-' . $height . '-' . json_encode($resizeSettings) . '-' . (string)$format);
218+
if (isset($this->tempCache[$cacheKey])) {
219+
return $this->tempCache[$cacheKey];
220+
}
221+
214222
if ($resultUrl = $this->cache->load($cacheKey)) {
223+
$this->tempCache[$cacheKey] = $resultUrl;
215224
return $resultUrl;
216225
}
217226

@@ -270,6 +279,7 @@ public function resizeAndGetUrl(string $imagePath, $width, $height, array $resiz
270279
}
271280

272281
$this->cache->save($resultUrl, $cacheKey, [self::CACHE_TAG_IDENTIFIER]);
282+
$this->tempCache[$cacheKey] = $resultUrl;
273283
} catch (\Exception $e) {
274284
$this->logger->error("Web200_ImageResize: could not resize image: ".$imagePath." \n" . $e->getMessage());
275285
}

0 commit comments

Comments
 (0)