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 version cache key
34
+ */
35
+ const VERSION_CACHE_KEY = 'mage-version ' ;
36
+
31
37
/**
32
38
* Product version
33
39
*
@@ -47,11 +53,21 @@ class ProductMetadata implements ProductMetadataInterface
47
53
private $ composerInformation ;
48
54
49
55
/**
56
+ * @var CacheInterface
57
+ */
58
+ private $ cache ;
59
+
60
+ /**
61
+ * ProductMetadata constructor.
50
62
* @param ComposerJsonFinder $composerJsonFinder
63
+ * @param \Magento\Framework\App\CacheInterface $cache
51
64
*/
52
- public function __construct (ComposerJsonFinder $ composerJsonFinder )
53
- {
65
+ public function __construct (
66
+ ComposerJsonFinder $ composerJsonFinder ,
67
+ CacheInterface $ cache = null
68
+ ) {
54
69
$ this ->composerJsonFinder = $ composerJsonFinder ;
70
+ $ this ->cache = $ cache ?? ObjectManager::getInstance ()->get (CacheInterface::class);
55
71
}
56
72
57
73
/**
@@ -61,13 +77,16 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
61
77
*/
62
78
public function getVersion ()
63
79
{
80
+ $ versionFromCache = $ this ->cache ->load (self ::VERSION_CACHE_KEY );
81
+ $ this ->version = $ this ->version ?: $ versionFromCache ;
64
82
if (!$ this ->version ) {
65
83
if (!($ this ->version = $ this ->getSystemPackageVersion ())) {
66
84
if ($ this ->getComposerInformation ()->isMagentoRoot ()) {
67
85
$ this ->version = $ this ->getComposerInformation ()->getRootPackage ()->getPrettyVersion ();
68
86
} else {
69
87
$ this ->version = 'UNKNOWN ' ;
70
88
}
89
+ $ this ->cache ->save ($ this ->version , self ::VERSION_CACHE_KEY , [Config::CACHE_TAG ]);
71
90
}
72
91
}
73
92
return $ this ->version ;
0 commit comments