6
6
namespace Magento \CacheInvalidate \Model ;
7
7
8
8
use Magento \Framework \Cache \InvalidateLogger ;
9
+ use Magento \PageCache \Model \Cache \Server ;
10
+ use Laminas \Http \Client \Adapter \Socket ;
11
+ use Laminas \Uri \Uri ;
9
12
10
13
/**
11
14
* Invalidate external HTTP cache(s) based on tag pattern
@@ -15,12 +18,12 @@ class PurgeCache
15
18
const HEADER_X_MAGENTO_TAGS_PATTERN = 'X-Magento-Tags-Pattern ' ;
16
19
17
20
/**
18
- * @var \Magento\PageCache\Model\Cache\ Server
21
+ * @var Server
19
22
*/
20
23
protected $ cacheServer ;
21
24
22
25
/**
23
- * @var \Magento\CacheInvalidate\Model\ SocketFactory
26
+ * @var SocketFactory
24
27
*/
25
28
protected $ socketAdapterFactory ;
26
29
@@ -39,26 +42,26 @@ class PurgeCache
39
42
*
40
43
* @var int
41
44
*/
42
- private $ requestSize ;
45
+ private $ maxHeaderSize ;
43
46
44
47
/**
45
48
* Constructor
46
49
*
47
- * @param \Magento\PageCache\Model\Cache\ Server $cacheServer
48
- * @param \Magento\CacheInvalidate\Model\ SocketFactory $socketAdapterFactory
50
+ * @param Server $cacheServer
51
+ * @param SocketFactory $socketAdapterFactory
49
52
* @param InvalidateLogger $logger
50
53
* @param int $maxHeaderSize
51
54
*/
52
55
public function __construct (
53
- \ Magento \ PageCache \ Model \ Cache \ Server $ cacheServer ,
54
- \ Magento \ CacheInvalidate \ Model \ SocketFactory $ socketAdapterFactory ,
56
+ Server $ cacheServer ,
57
+ SocketFactory $ socketAdapterFactory ,
55
58
InvalidateLogger $ logger ,
56
59
int $ maxHeaderSize = 7680
57
60
) {
58
61
$ this ->cacheServer = $ cacheServer ;
59
62
$ this ->socketAdapterFactory = $ socketAdapterFactory ;
60
63
$ this ->logger = $ logger ;
61
- $ this ->requestSize = $ maxHeaderSize ;
64
+ $ this ->maxHeaderSize = $ maxHeaderSize ;
62
65
}
63
66
64
67
/**
@@ -94,13 +97,13 @@ public function sendPurgeRequest($tags)
94
97
* @param array $tags
95
98
* @return \Generator
96
99
*/
97
- private function chunkTags ($ tags )
100
+ private function chunkTags (array $ tags ): \ Generator
98
101
{
99
102
$ currentBatchSize = 0 ;
100
103
$ formattedTagsChunk = [];
101
104
foreach ($ tags as $ formattedTag ) {
102
105
// Check if (currentBatchSize + length of next tag + number of pipe delimiters) would exceed header size.
103
- if ($ currentBatchSize + strlen ($ formattedTag ) + count ($ formattedTagsChunk ) > $ this ->requestSize ) {
106
+ if ($ currentBatchSize + strlen ($ formattedTag ) + count ($ formattedTagsChunk ) > $ this ->maxHeaderSize ) {
104
107
yield implode ('| ' , $ formattedTagsChunk );
105
108
$ formattedTagsChunk = [];
106
109
$ currentBatchSize = 0 ;
@@ -117,12 +120,12 @@ private function chunkTags($tags)
117
120
/**
118
121
* Send curl purge request to servers to invalidate cache by tags pattern
119
122
*
120
- * @param \Laminas\Http\Client\Adapter\ Socket $socketAdapter
121
- * @param \Laminas\Uri\ Uri[] $servers
123
+ * @param Socket $socketAdapter
124
+ * @param Uri[] $servers
122
125
* @param string $formattedTagsChunk
123
126
* @return bool Return true if successful; otherwise return false
124
127
*/
125
- private function sendPurgeRequestToServers ($ socketAdapter , $ servers , $ formattedTagsChunk )
128
+ private function sendPurgeRequestToServers (Socket $ socketAdapter , array $ servers , string $ formattedTagsChunk ): bool
126
129
{
127
130
$ headers = [self ::HEADER_X_MAGENTO_TAGS_PATTERN => $ formattedTagsChunk ];
128
131
$ unresponsiveServerError = [];
0 commit comments