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