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