Skip to content

Commit

Permalink
Merge pull request #59 from kitsunet/feature/runtime-cache-src
Browse files Browse the repository at this point in the history
FEATURE: Runtime cache for `src` method of `AssetImageSource`
  • Loading branch information
mficzel committed Nov 3, 2023
2 parents c9512ff + 7444ea8 commit e0ed8f4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Classes/Domain/AssetImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class AssetImageSource extends AbstractScalableImageSource
*/
protected $request;

/**
* Runtime cache for the src uri for the asset.
*
* @var string|null
*/
private $srcCache = null;

/**
* @param ImageInterface $asset
* @param string|null $title
Expand Down Expand Up @@ -112,6 +119,10 @@ public function src(): string
return '';
}

if ($this->srcCache !== null) {
return $this->srcCache;
}

$width = $this->getCurrentWidth();
$height = $this->getCurrentHeight();

Expand All @@ -136,11 +147,14 @@ public function src(): string
$this->request
);

if ($thumbnailData === null) {
return '';
}
$this->srcCache = ($thumbnailData === null) ? '' : $thumbnailData['src'];

return $thumbnailData['src'];
return $this->srcCache;
}

public function __clone(): void
{
$this->srcCache = null;
}

public function dataSrc(): string
Expand Down

0 comments on commit e0ed8f4

Please sign in to comment.