1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © Magento, Inc. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
6
+ declare (strict_types=1 );
7
+
7
8
namespace Magento \Framework \App \Cache ;
8
9
10
+ use Magento \Framework \App \Cache \Tag \Resolver ;
11
+ use Magento \Framework \App \Cache \Type \FrontendPool ;
12
+ use Magento \Framework \Model \AbstractModel ;
13
+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
14
+
9
15
/**
10
16
* Automatic cache cleaner plugin
11
17
*/
12
18
class FlushCacheByTags
13
19
{
14
20
/**
15
- * @var Type\ FrontendPool
21
+ * @var FrontendPool
16
22
*/
17
23
private $ cachePool ;
18
24
@@ -27,23 +33,21 @@ class FlushCacheByTags
27
33
private $ cacheState ;
28
34
29
35
/**
30
- * @var Tag\ Resolver
36
+ * @var Resolver
31
37
*/
32
38
private $ tagResolver ;
33
39
34
40
/**
35
- * FlushCacheByTags constructor.
36
- *
37
- * @param Type\FrontendPool $cachePool
41
+ * @param FrontendPool $cachePool
38
42
* @param StateInterface $cacheState
39
- * @param array $cacheList
40
- * @param Tag\ Resolver $tagResolver
43
+ * @param string[] $cacheList
44
+ * @param Resolver $tagResolver
41
45
*/
42
46
public function __construct (
43
- \ Magento \ Framework \ App \ Cache \ Type \ FrontendPool $ cachePool ,
44
- \ Magento \ Framework \ App \ Cache \ StateInterface $ cacheState ,
47
+ FrontendPool $ cachePool ,
48
+ StateInterface $ cacheState ,
45
49
array $ cacheList ,
46
- \ Magento \ Framework \ App \ Cache \ Tag \ Resolver $ tagResolver
50
+ Resolver $ tagResolver
47
51
) {
48
52
$ this ->cachePool = $ cachePool ;
49
53
$ this ->cacheState = $ cacheState ;
@@ -54,17 +58,14 @@ public function __construct(
54
58
/**
55
59
* Clean cache on save object
56
60
*
57
- * @param \Magento\Framework\Model\ResourceModel\ AbstractResource $subject
61
+ * @param AbstractResource $subject
58
62
* @param \Closure $proceed
59
- * @param \Magento\Framework\Model\ AbstractModel $object
60
- * @return \Magento\Framework\Model\ResourceModel\ AbstractResource
63
+ * @param AbstractModel $object
64
+ * @return AbstractResource
61
65
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
62
66
*/
63
- public function aroundSave (
64
- \Magento \Framework \Model \ResourceModel \AbstractResource $ subject ,
65
- \Closure $ proceed ,
66
- \Magento \Framework \Model \AbstractModel $ object
67
- ) {
67
+ public function aroundSave (AbstractResource $ subject , \Closure $ proceed , AbstractModel $ object ): AbstractResource
68
+ {
68
69
$ result = $ proceed ($ object );
69
70
$ tags = $ this ->tagResolver ->getTags ($ object );
70
71
$ this ->cleanCacheByTags ($ tags );
@@ -75,39 +76,37 @@ public function aroundSave(
75
76
/**
76
77
* Clean cache on delete object
77
78
*
78
- * @param \Magento\Framework\Model\ResourceModel\ AbstractResource $subject
79
+ * @param AbstractResource $subject
79
80
* @param \Closure $proceed
80
- * @param \Magento\Framework\Model\ AbstractModel $object
81
- * @return \Magento\Framework\Model\ResourceModel\ AbstractResource
81
+ * @param AbstractModel $object
82
+ * @return AbstractResource
82
83
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
83
84
*/
84
- public function aroundDelete (
85
- \Magento \Framework \Model \ResourceModel \AbstractResource $ subject ,
86
- \Closure $ proceed ,
87
- \Magento \Framework \Model \AbstractModel $ object
88
- ) {
85
+ public function aroundDelete (AbstractResource $ subject , \Closure $ proceed , AbstractModel $ object ): AbstractResource
86
+ {
89
87
$ tags = $ this ->tagResolver ->getTags ($ object );
90
88
$ result = $ proceed ($ object );
91
89
$ this ->cleanCacheByTags ($ tags );
90
+
92
91
return $ result ;
93
92
}
94
93
95
94
/**
96
95
* Clean cache by tags
97
96
*
98
- * @param string[] $tags
97
+ * @param string[] $tags
99
98
* @return void
100
99
*/
101
- private function cleanCacheByTags ($ tags )
100
+ private function cleanCacheByTags (array $ tags ): void
102
101
{
103
- if (empty ( $ tags) ) {
102
+ if (! $ tags ) {
104
103
return ;
105
104
}
106
105
foreach ($ this ->cacheList as $ cacheType ) {
107
106
if ($ this ->cacheState ->isEnabled ($ cacheType )) {
108
107
$ this ->cachePool ->get ($ cacheType )->clean (
109
- \Zend_Cache::CLEANING_MODE_MATCHING_TAG ,
110
- array_unique ($ tags )
108
+ \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG ,
109
+ \ array_unique ($ tags )
111
110
);
112
111
}
113
112
}
0 commit comments