From f0856e8575bc0cc86543d14da2bd45d8e457fa25 Mon Sep 17 00:00:00 2001 From: David Verholen Date: Tue, 6 Aug 2019 12:39:54 +0200 Subject: [PATCH] 24025 add caching for magento product version fixes https://github.com/magento/magento2/issues/24025 --- .../Magento/Framework/App/ProductMetadata.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ProductMetadata.php b/lib/internal/Magento/Framework/App/ProductMetadata.php index c9fde94352a71..2829292555790 100644 --- a/lib/internal/Magento/Framework/App/ProductMetadata.php +++ b/lib/internal/Magento/Framework/App/ProductMetadata.php @@ -8,9 +8,9 @@ namespace Magento\Framework\App; use Magento\Framework\Composer\ComposerFactory; -use \Magento\Framework\Composer\ComposerJsonFinder; -use \Magento\Framework\App\Filesystem\DirectoryList; -use \Magento\Framework\Composer\ComposerInformation; +use Magento\Framework\Composer\ComposerJsonFinder; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Composer\ComposerInformation; /** * Class ProductMetadata @@ -28,6 +28,11 @@ class ProductMetadata implements ProductMetadataInterface */ const PRODUCT_NAME = 'Magento'; + /** + * Magento Product Version Cache Key + */ + const MAGENTO_PRODUCT_VERSION_CACHE_KEY = 'magento-product-version'; + /** * Product version * @@ -45,13 +50,19 @@ class ProductMetadata implements ProductMetadataInterface * @var \Magento\Framework\Composer\ComposerInformation */ private $composerInformation; + /** + * @var CacheInterface + */ + private $cache; /** * @param ComposerJsonFinder $composerJsonFinder + * @param CacheInterface|null $cache */ - public function __construct(ComposerJsonFinder $composerJsonFinder) + public function __construct(ComposerJsonFinder $composerJsonFinder, CacheInterface $cache = null) { $this->composerJsonFinder = $composerJsonFinder; + $this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class); } /** @@ -61,6 +72,9 @@ public function __construct(ComposerJsonFinder $composerJsonFinder) */ public function getVersion() { + if ($cachedVersion = $this->cache->load(self::MAGENTO_PRODUCT_VERSION_CACHE_KEY)) { + $this->version = $cachedVersion; + } if (!$this->version) { if (!($this->version = $this->getSystemPackageVersion())) { if ($this->getComposerInformation()->isMagentoRoot()) { @@ -69,6 +83,7 @@ public function getVersion() $this->version = 'UNKNOWN'; } } + $this->cache->save($this->version, self::MAGENTO_PRODUCT_VERSION_CACHE_KEY); } return $this->version; }