@@ -33,7 +33,7 @@ class Cache
33
33
public const REDIS_BACKEND_REDIS_CACHE = '\Magento\Framework\Cache\Backend\Redis ' ;
34
34
35
35
public const VALKEY_BACKEND_CM_CACHE = 'Cm_Cache_Backend_Redis ' ;
36
- public const VALKEY_BACKEND_VALKEY_CACHE = '\Magento\Framework\Cache\Backend\Valkey ' ;
36
+ public const VALKEY_BACKEND_VALKEY_CACHE = '\Magento\Framework\Cache\Backend\Redis ' ;
37
37
38
38
public const VALKEY_BACKEND_REMOTE_SYNCHRONIZED_CACHE = '\Magento\Framework\Cache\Backend\RemoteSynchronizedCache ' ;
39
39
public const REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE = '\Magento\Framework\Cache\Backend\RemoteSynchronizedCache ' ;
@@ -76,11 +76,11 @@ class Cache
76
76
private ConfigMerger $ configMerger ;
77
77
78
78
/**
79
- * @param Valkey $valkey
80
- * @param Redis $redis
79
+ * @param Valkey $valkey
80
+ * @param Redis $redis
81
81
* @param DeployInterface $stageConfig
82
82
* @param LoggerInterface $logger
83
- * @param ConfigMerger $configMerger
83
+ * @param ConfigMerger $configMerger
84
84
*/
85
85
public function __construct (
86
86
Redis $ redis ,
@@ -103,6 +103,7 @@ public function __construct(
103
103
* configuration in relationships and if so, makes cache configuration for redis.
104
104
* Returns an empty array in other case.
105
105
*
106
+ * @SuppressWarnings("CyclomaticComplexity")
106
107
* @return array
107
108
* @throws ConfigException
108
109
*/
@@ -147,11 +148,10 @@ public function get(): array
147
148
}
148
149
149
150
// Determine backend based on available configuration
150
- $ backendConfig = !empty ($ redisConfig ) ? $ redisConfig : $ valkeyConfig ;
151
- $ envCacheBackendModel = (string )$ this ->stageConfig ->get (DeployInterface::VAR_CACHE_REDIS_BACKEND );
152
-
151
+ $ backendConfig = !empty ($ redisConfig ) ? $ redisConfig : $ valkeyConfig ;
152
+ $ cacheBackendModel = !empty ($ redisConfig ) ? $ envCacheRadisBackendModel :$ envCacheValkeyBackendModel ;
153
153
if ($ this ->isSynchronizedConfigStructure ()) {
154
- $ cacheCacheBackend = $ this ->getSynchronizedConfigStructure ($ envCacheBackendModel , $ backendConfig );
154
+ $ cacheCacheBackend = $ this ->getSynchronizedConfigStructure ($ cacheBackendModel , $ backendConfig );
155
155
$ cacheCacheBackend ['backend_options ' ]['remote_backend_options ' ] = array_merge (
156
156
$ cacheCacheBackend ['backend_options ' ]['remote_backend_options ' ],
157
157
$ this ->getSlaveConnection ($ envCacheConfiguration , $ backendConfig )
@@ -165,14 +165,14 @@ public function get(): array
165
165
],
166
166
];
167
167
} else {
168
- $ cacheCacheBackend = $ this ->getUnsyncedConfigStructure ($ envCacheBackendModel , $ backendConfig );
168
+ $ cacheCacheBackend = $ this ->getUnsyncedConfigStructure ($ cacheBackendModel , $ backendConfig );
169
169
$ slaveConnection = $ this ->getSlaveConnection ($ envCacheConfiguration , $ backendConfig );
170
170
if ($ slaveConnection ) {
171
171
$ cacheCacheBackend ['frontend_options ' ]['write_control ' ] = false ;
172
- $ cacheCacheBackend ['backend_options ' ] = array_merge (
173
- $ cacheCacheBackend ['backend_options ' ],
174
- $ slaveConnection
175
- );
172
+ $ cacheCacheBackend ['backend_options ' ] = array_merge (
173
+ $ cacheCacheBackend ['backend_options ' ],
174
+ $ slaveConnection
175
+ );
176
176
}
177
177
$ finalConfig = [
178
178
'frontend ' => [
@@ -197,8 +197,8 @@ public function get(): array
197
197
* also if CACHE_CONFIGURATION is compatible with slave connections.
198
198
* Otherwise, retrieves an empty array.
199
199
*
200
- * @param array $envCacheConfiguration
201
- * @param array $backendConfig
200
+ * @param array $envCacheConfiguration
201
+ * @param array $backendConfig
202
202
* @return array
203
203
* @throws ConfigException
204
204
*/
@@ -232,24 +232,25 @@ private function getSlaveConnection(array $envCacheConfiguration, array $backend
232
232
233
233
$ this ->logger ->info (sprintf ('Set %s slave connection ' , $ backendType ));
234
234
} else {
235
- $ this ->logger ->notice (
236
- sprintf (
237
- 'The variable \'%s \' is ignored as you \'ve changed cache connection settings in \'%s \'' ,
238
- $ useRedisSlave ? DeployInterface::VAR_REDIS_USE_SLAVE_CONNECTION : DeployInterface::VAR_VALKEY_USE_SLAVE_CONNECTION ,
239
- DeployInterface::VAR_CACHE_CONFIGURATION
240
- )
241
- );
235
+ $ this ->logger ->notice (
236
+ sprintf (
237
+ 'The variable \'%s \' is ignored as you \'ve changed cache connection settings in \'%s \'' ,
238
+ $ useRedisSlave ?
239
+ DeployInterface::VAR_REDIS_USE_SLAVE_CONNECTION :
240
+ DeployInterface::VAR_VALKEY_USE_SLAVE_CONNECTION ,
241
+ DeployInterface::VAR_CACHE_CONFIGURATION
242
+ )
243
+ );
242
244
}
243
245
}
244
246
245
-
246
247
return $ config ;
247
248
}
248
249
249
250
/**
250
251
* Checks that given cache configuration is valid.
251
252
*
252
- * @param array $cacheConfiguration
253
+ * @param array $cacheConfiguration
253
254
* @return bool
254
255
*/
255
256
private function isCacheConfigurationValid (array $ cacheConfiguration ): bool
@@ -263,10 +264,10 @@ private function isCacheConfigurationValid(array $cacheConfiguration): bool
263
264
*
264
265
* Returns false if server or port was changed in merged configuration otherwise false.
265
266
*
266
- * @param array $envCacheConfig
267
- * @param array $backendConfig
268
- * @return bool
269
- * @throws ConfigException
267
+ * @param array $envCacheConfig
268
+ * @param array $backendConfig
269
+ * @return bool
270
+ * @throws ConfigException
270
271
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
271
272
*/
272
273
private function isConfigurationCompatibleWithSlaveConnection (
@@ -281,7 +282,8 @@ private function isConfigurationCompatibleWithSlaveConnection(
281
282
?? null ;
282
283
283
284
if (($ host !== null && $ host !== $ backendConfig ['host ' ])
284
- || ($ port !== null && $ port !== $ backendConfig ['port ' ])) {
285
+ || ($ port !== null && $ port !== $ backendConfig ['port ' ])
286
+ ) {
285
287
return false ;
286
288
}
287
289
} else {
@@ -290,7 +292,8 @@ private function isConfigurationCompatibleWithSlaveConnection(
290
292
$ port = $ envCacheConfig ['frontend ' ][$ type ]['backend_options ' ]['port ' ] ?? null ;
291
293
292
294
if (($ host !== null && $ host !== $ backendConfig ['host ' ])
293
- || ($ port !== null && $ port !== $ backendConfig ['port ' ])) {
295
+ || ($ port !== null && $ port !== $ backendConfig ['port ' ])
296
+ ) {
294
297
return false ;
295
298
}
296
299
}
@@ -302,15 +305,14 @@ private function isConfigurationCompatibleWithSlaveConnection(
302
305
/**
303
306
* Returns backend config for unsynced cache implementation.
304
307
*
305
- * @param string $envCacheBackendModel
306
- * @param array $backendConfig
308
+ * @param string $envCacheBackendModel
309
+ * @param array $backendConfig
307
310
* @return array
308
311
*/
309
312
private function getUnsyncedConfigStructure (string $ envCacheBackendModel , array $ backendConfig ): array
310
313
{
311
- $ cacheBackendModelRedis ='Cm_Cache_Backend_Redis ' ;
312
- $ config = [
313
- 'backend ' => $ cacheBackendModelRedis ,
314
+ $ config = [
315
+ 'backend ' => $ envCacheBackendModel ,
314
316
'backend_options ' => [
315
317
'server ' => $ backendConfig ['host ' ],
316
318
'port ' => $ backendConfig ['port ' ],
@@ -327,20 +329,17 @@ private function getUnsyncedConfigStructure(string $envCacheBackendModel, array
327
329
/**
328
330
* Returns backend config for synchronized cache implementation.
329
331
*
330
- * @param string $envCacheBackendModel
331
- * @param array $backendConfig
332
+ * @param string $envCacheBackendModel
333
+ * @param array $backendConfig
332
334
* @return array
333
335
*/
334
336
private function getSynchronizedConfigStructure (string $ envCacheBackendModel , array $ backendConfig ): array
335
337
{
336
- $ backendClass = $ backendConfig ['host ' ] === 'valkey '
337
- ? '\Magento\Framework\Cache\Backend\Valkey '
338
- : '\Magento\Framework\Cache\Backend\Redis ' ;
339
338
340
339
$ config = [
341
340
'backend ' => $ envCacheBackendModel ,
342
341
'backend_options ' => [
343
- 'remote_backend ' => $ backendClass ,
342
+ 'remote_backend ' => ' \Magento\Framework\Cache\Backend\Redis ' ,
344
343
'remote_backend_options ' => [
345
344
'server ' => $ backendConfig ['host ' ],
346
345
'port ' => $ backendConfig ['port ' ],
@@ -377,15 +376,14 @@ private function isSynchronizedConfigStructure(): bool
377
376
$ redisModel = (string )$ this ->stageConfig ->get (DeployInterface::VAR_CACHE_REDIS_BACKEND );
378
377
$ valkeyModel = (string )$ this ->stageConfig ->get (DeployInterface::VAR_CACHE_VALKEY_BACKEND );
379
378
return $ redisModel === self ::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE ||
380
- $ valkeyModel === self ::VALKEY_BACKEND_REMOTE_SYNCHRONIZED_CACHE ;
379
+ $ valkeyModel === self ::VALKEY_BACKEND_REMOTE_SYNCHRONIZED_CACHE ;
381
380
}
382
381
383
- /**
384
- * @return array
385
- */
386
- public function isValkeyEnabled ()
387
- {
388
- return $ this ->valkey ->getConfiguration ();
389
- }
390
-
382
+ /**
383
+ * @return array
384
+ */
385
+ public function isValkeyEnabled (): array
386
+ {
387
+ return $ this ->valkey ->getConfiguration ();
388
+ }
391
389
}
0 commit comments