Skip to content

Commit f0856e8

Browse files
author
David Verholen
committed
24025 add caching for magento product version
fixes #24025
1 parent cc23756 commit f0856e8

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Magento\Framework\App;
99

1010
use Magento\Framework\Composer\ComposerFactory;
11-
use \Magento\Framework\Composer\ComposerJsonFinder;
12-
use \Magento\Framework\App\Filesystem\DirectoryList;
13-
use \Magento\Framework\Composer\ComposerInformation;
11+
use Magento\Framework\Composer\ComposerJsonFinder;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Composer\ComposerInformation;
1414

1515
/**
1616
* Class ProductMetadata
@@ -28,6 +28,11 @@ class ProductMetadata implements ProductMetadataInterface
2828
*/
2929
const PRODUCT_NAME = 'Magento';
3030

31+
/**
32+
* Magento Product Version Cache Key
33+
*/
34+
const MAGENTO_PRODUCT_VERSION_CACHE_KEY = 'magento-product-version';
35+
3136
/**
3237
* Product version
3338
*
@@ -45,13 +50,19 @@ class ProductMetadata implements ProductMetadataInterface
4550
* @var \Magento\Framework\Composer\ComposerInformation
4651
*/
4752
private $composerInformation;
53+
/**
54+
* @var CacheInterface
55+
*/
56+
private $cache;
4857

4958
/**
5059
* @param ComposerJsonFinder $composerJsonFinder
60+
* @param CacheInterface|null $cache
5161
*/
52-
public function __construct(ComposerJsonFinder $composerJsonFinder)
62+
public function __construct(ComposerJsonFinder $composerJsonFinder, CacheInterface $cache = null)
5363
{
5464
$this->composerJsonFinder = $composerJsonFinder;
65+
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
5566
}
5667

5768
/**
@@ -61,6 +72,9 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
6172
*/
6273
public function getVersion()
6374
{
75+
if ($cachedVersion = $this->cache->load(self::MAGENTO_PRODUCT_VERSION_CACHE_KEY)) {
76+
$this->version = $cachedVersion;
77+
}
6478
if (!$this->version) {
6579
if (!($this->version = $this->getSystemPackageVersion())) {
6680
if ($this->getComposerInformation()->isMagentoRoot()) {
@@ -69,6 +83,7 @@ public function getVersion()
6983
$this->version = 'UNKNOWN';
7084
}
7185
}
86+
$this->cache->save($this->version, self::MAGENTO_PRODUCT_VERSION_CACHE_KEY);
7287
}
7388
return $this->version;
7489
}

0 commit comments

Comments
 (0)