Skip to content

Commit e3c4e9c

Browse files
authored
ENGCOM-5554: 24025 add caching for magento product version #24030
2 parents e96558c + 645b2a8 commit e3c4e9c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
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
17+
*
1718
* @package Magento\Framework\App
1819
*/
1920
class ProductMetadata implements ProductMetadataInterface
@@ -28,6 +29,11 @@ class ProductMetadata implements ProductMetadataInterface
2829
*/
2930
const PRODUCT_NAME = 'Magento';
3031

32+
/**
33+
* Magento Product Version Cache Key
34+
*/
35+
private const MAGENTO_PRODUCT_VERSION_CACHE_KEY = 'magento-product-version';
36+
3137
/**
3238
* Product version
3339
*
@@ -46,12 +52,19 @@ class ProductMetadata implements ProductMetadataInterface
4652
*/
4753
private $composerInformation;
4854

55+
/**
56+
* @var CacheInterface
57+
*/
58+
private $cache;
59+
4960
/**
5061
* @param ComposerJsonFinder $composerJsonFinder
62+
* @param CacheInterface|null $cache
5163
*/
52-
public function __construct(ComposerJsonFinder $composerJsonFinder)
64+
public function __construct(ComposerJsonFinder $composerJsonFinder, CacheInterface $cache = null)
5365
{
5466
$this->composerJsonFinder = $composerJsonFinder;
67+
$this->cache = $cache ?: ObjectManager::getInstance()->get(CacheInterface::class);
5568
}
5669

5770
/**
@@ -61,6 +74,9 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
6174
*/
6275
public function getVersion()
6376
{
77+
if ($cachedVersion = $this->cache->load(self::MAGENTO_PRODUCT_VERSION_CACHE_KEY)) {
78+
$this->version = $cachedVersion;
79+
}
6480
if (!$this->version) {
6581
if (!($this->version = $this->getSystemPackageVersion())) {
6682
if ($this->getComposerInformation()->isMagentoRoot()) {
@@ -69,6 +85,7 @@ public function getVersion()
6985
$this->version = 'UNKNOWN';
7086
}
7187
}
88+
$this->cache->save($this->version, self::MAGENTO_PRODUCT_VERSION_CACHE_KEY);
7289
}
7390
return $this->version;
7491
}

0 commit comments

Comments
 (0)