From 576d216f2abf7cac452fabd17e314dac413b4426 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Mon, 10 May 2021 18:07:31 +0300 Subject: [PATCH 1/2] v1.14.9: Added registry cache to transformation queries --- Model/Transformation.php | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Model/Transformation.php b/Model/Transformation.php index 954f53c..e5b5295 100644 --- a/Model/Transformation.php +++ b/Model/Transformation.php @@ -13,6 +13,11 @@ class Transformation extends AbstractModel { + /** + * @var string + */ + private $imageNameCacheKey; + private $configuration; /** @@ -74,6 +79,27 @@ public function getFreeTransformation() return $this->getData('free_transformation'); } + /** + * @method cacheResult + * @param bool $result + * @return mixed + */ + private function cacheResult($result) + { + $this->_registry->unregister($this->imageNameCacheKey); + $this->_registry->register($this->imageNameCacheKey, $result); + return $result; + } + + /** + * @method cacheResult + * @return mixed + */ + private function getFromCache() + { + return $this->_registry->registry($this->imageNameCacheKey); + } + /** * @param string $imageFile * @return ImageTransformation @@ -89,13 +115,21 @@ public function transformationForImage($imageFile) /** * @param ImageTransformation $transformation * @param string $imageFile + * @param bool $refresh * @return ImageTransformation */ - public function addFreeformTransformationForImage(ImageTransformation $transformation, $imageFile) + public function addFreeformTransformationForImage(ImageTransformation $transformation, $imageFile, $refresh = false) { - $this->load($imageFile); - if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) { - $transformation->withFreeform(Freeform::fromString($this->getFreeTransformation())); + $this->imageNameCacheKey = 'cldtransformcachekey_' . (string) $imageFile; + if (!$refresh && ($cacheResult = $this->getFromCache()) !== null) { + if (($cacheResult->getImageName() === $imageFile) && $cacheResult->hasFreeTransformation()) { + $transformation->withFreeform(Freeform::fromString($cacheResult->getFreeTransformation())); + } + } else { + $this->load($imageFile); + if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) { + $transformation->withFreeform(Freeform::fromString($this->getFreeTransformation())); + } } return $transformation; From 5a97ad769f0f12bb0f6793697d642cbbbea8f2ae Mon Sep 17 00:00:00 2001 From: pini-girit Date: Mon, 10 May 2021 18:14:08 +0300 Subject: [PATCH 2/2] v1.14.9: Removed registry cache from transformation queries - needs improvments --- Model/Transformation.php | 42 ++++------------------------------------ 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/Model/Transformation.php b/Model/Transformation.php index e5b5295..954f53c 100644 --- a/Model/Transformation.php +++ b/Model/Transformation.php @@ -13,11 +13,6 @@ class Transformation extends AbstractModel { - /** - * @var string - */ - private $imageNameCacheKey; - private $configuration; /** @@ -79,27 +74,6 @@ public function getFreeTransformation() return $this->getData('free_transformation'); } - /** - * @method cacheResult - * @param bool $result - * @return mixed - */ - private function cacheResult($result) - { - $this->_registry->unregister($this->imageNameCacheKey); - $this->_registry->register($this->imageNameCacheKey, $result); - return $result; - } - - /** - * @method cacheResult - * @return mixed - */ - private function getFromCache() - { - return $this->_registry->registry($this->imageNameCacheKey); - } - /** * @param string $imageFile * @return ImageTransformation @@ -115,21 +89,13 @@ public function transformationForImage($imageFile) /** * @param ImageTransformation $transformation * @param string $imageFile - * @param bool $refresh * @return ImageTransformation */ - public function addFreeformTransformationForImage(ImageTransformation $transformation, $imageFile, $refresh = false) + public function addFreeformTransformationForImage(ImageTransformation $transformation, $imageFile) { - $this->imageNameCacheKey = 'cldtransformcachekey_' . (string) $imageFile; - if (!$refresh && ($cacheResult = $this->getFromCache()) !== null) { - if (($cacheResult->getImageName() === $imageFile) && $cacheResult->hasFreeTransformation()) { - $transformation->withFreeform(Freeform::fromString($cacheResult->getFreeTransformation())); - } - } else { - $this->load($imageFile); - if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) { - $transformation->withFreeform(Freeform::fromString($this->getFreeTransformation())); - } + $this->load($imageFile); + if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) { + $transformation->withFreeform(Freeform::fromString($this->getFreeTransformation())); } return $transformation;