8
8
namespace Magento \Framework \App ;
9
9
10
10
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 ;
14
14
15
15
/**
16
16
* Class ProductMetadata
@@ -28,6 +28,11 @@ class ProductMetadata implements ProductMetadataInterface
28
28
*/
29
29
const PRODUCT_NAME = 'Magento ' ;
30
30
31
+ /**
32
+ * Magento Product Version Cache Key
33
+ */
34
+ const MAGENTO_PRODUCT_VERSION_CACHE_KEY = 'magento-product-version ' ;
35
+
31
36
/**
32
37
* Product version
33
38
*
@@ -45,13 +50,19 @@ class ProductMetadata implements ProductMetadataInterface
45
50
* @var \Magento\Framework\Composer\ComposerInformation
46
51
*/
47
52
private $ composerInformation ;
53
+ /**
54
+ * @var CacheInterface
55
+ */
56
+ private $ cache ;
48
57
49
58
/**
50
59
* @param ComposerJsonFinder $composerJsonFinder
60
+ * @param CacheInterface|null $cache
51
61
*/
52
- public function __construct (ComposerJsonFinder $ composerJsonFinder )
62
+ public function __construct (ComposerJsonFinder $ composerJsonFinder, CacheInterface $ cache = null )
53
63
{
54
64
$ this ->composerJsonFinder = $ composerJsonFinder ;
65
+ $ this ->cache = $ cache ?: ObjectManager::getInstance ()->get (CacheInterface::class);
55
66
}
56
67
57
68
/**
@@ -61,6 +72,9 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
61
72
*/
62
73
public function getVersion ()
63
74
{
75
+ if ($ cachedVersion = $ this ->cache ->load (self ::MAGENTO_PRODUCT_VERSION_CACHE_KEY )) {
76
+ $ this ->version = $ cachedVersion ;
77
+ }
64
78
if (!$ this ->version ) {
65
79
if (!($ this ->version = $ this ->getSystemPackageVersion ())) {
66
80
if ($ this ->getComposerInformation ()->isMagentoRoot ()) {
@@ -69,6 +83,7 @@ public function getVersion()
69
83
$ this ->version = 'UNKNOWN ' ;
70
84
}
71
85
}
86
+ $ this ->cache ->save ($ this ->version , self ::MAGENTO_PRODUCT_VERSION_CACHE_KEY );
72
87
}
73
88
return $ this ->version ;
74
89
}
0 commit comments