cache = $cache; $this->serializer = $serializer; $this->cacheState = $cacheState; } /** * @param AttributeResource $subject * @param callable $proceed * @param int $attributeId * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetStoreLabelsByAttributeId( AttributeResource $subject, \Closure $proceed, $attributeId ) { $cacheId = self::STORE_LABEL_ATTRIBUTE . $attributeId; if ($this->isCacheEnabled() && ($storeLabels = $this->cache->load($cacheId))) { return $this->serializer->unserialize($storeLabels); } $storeLabels = $proceed($attributeId); if ($this->isCacheEnabled()) { $this->cache->save( $this->serializer->serialize($storeLabels), $cacheId, [ Type::CACHE_TAG, EntityAttribute::CACHE_TAG ] ); } return $storeLabels; } /** * Check if cache is enabled * * @return bool */ private function isCacheEnabled() { return $this->cacheState->isEnabled(Type::TYPE_IDENTIFIER); } }