Skip to content

Commit

Permalink
24025 add caching for magento product version
Browse files Browse the repository at this point in the history
fixes #24025
  • Loading branch information
David Verholen committed Aug 6, 2019
1 parent cc23756 commit f0856e8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/internal/Magento/Framework/App/ProductMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand All @@ -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);
}

/**
Expand All @@ -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()) {
Expand All @@ -69,6 +83,7 @@ public function getVersion()
$this->version = 'UNKNOWN';
}
}
$this->cache->save($this->version, self::MAGENTO_PRODUCT_VERSION_CACHE_KEY);
}
return $this->version;
}
Expand Down

0 comments on commit f0856e8

Please sign in to comment.