1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
9
8
use Magento \Framework \App \ObjectManager ;
10
9
use Magento \Framework \Event \ObserverInterface ;
11
10
11
+ /**
12
+ * Class to flush cache by tags
13
+ */
12
14
class FlushCacheByTags implements ObserverInterface
13
15
{
14
16
/**
@@ -40,15 +42,25 @@ class FlushCacheByTags implements ObserverInterface
40
42
/**
41
43
* @param \Magento\PageCache\Model\Config $config
42
44
* @param \Magento\Framework\App\PageCache\Cache $cache
45
+ * @param \Magento\Framework\App\Cache\Tag\Resolver $tagResolver
46
+ * @param \Magento\PageCache\Model\Cache\Type $fullPageCache
43
47
*/
44
- public function __construct (\Magento \PageCache \Model \Config $ config , \Magento \Framework \App \PageCache \Cache $ cache )
45
- {
48
+ public function __construct (
49
+ \Magento \PageCache \Model \Config $ config ,
50
+ \Magento \Framework \App \PageCache \Cache $ cache ,
51
+ \Magento \Framework \App \Cache \Tag \Resolver $ tagResolver ,
52
+ \Magento \PageCache \Model \Cache \Type $ fullPageCache
53
+ ) {
46
54
$ this ->_config = $ config ;
47
55
$ this ->_cache = $ cache ;
56
+ $ this ->tagResolver = $ tagResolver ;
57
+ $ this ->fullPageCache = $ fullPageCache ;
48
58
}
49
59
50
60
/**
51
- * If Built-In caching is enabled it collects array of tags
61
+ * Flushes cache
62
+ *
63
+ * If built-in caching is enabled it collects array of tags
52
64
* of incoming object and asks to clean cache.
53
65
*
54
66
* @param \Magento\Framework\Event\Observer $observer
@@ -61,38 +73,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
61
73
if (!is_object ($ object )) {
62
74
return ;
63
75
}
64
- $ tags = $ this ->getTagResolver () ->getTags ($ object );
76
+ $ tags = $ this ->tagResolver ->getTags ($ object );
65
77
66
78
if (!empty ($ tags )) {
67
- $ this ->getCache () ->clean (\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG , array_unique ($ tags ));
79
+ $ this ->fullPageCache ->clean (\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG , array_unique ($ tags ));
68
80
}
69
81
}
70
82
}
71
-
72
- /**
73
- * TODO: Workaround to support backwards compatibility, will rework to use Dependency Injection in MAGETWO-49547
74
- *
75
- *
76
- * @return \Magento\PageCache\Model\Cache\Type
77
- */
78
- private function getCache ()
79
- {
80
- if (!$ this ->fullPageCache ) {
81
- $ this ->fullPageCache = ObjectManager::getInstance ()->get (\Magento \PageCache \Model \Cache \Type::class);
82
- }
83
- return $ this ->fullPageCache ;
84
- }
85
-
86
- /**
87
- * @deprecated 100.1.2
88
- * @return \Magento\Framework\App\Cache\Tag\Resolver
89
- */
90
- private function getTagResolver ()
91
- {
92
- if ($ this ->tagResolver === null ) {
93
- $ this ->tagResolver = \Magento \Framework \App \ObjectManager::getInstance ()
94
- ->get (\Magento \Framework \App \Cache \Tag \Resolver::class);
95
- }
96
- return $ this ->tagResolver ;
97
- }
98
83
}
0 commit comments