Skip to content

Commit 8873703

Browse files
committed
ACP2E-684: FPC is indicated as disabled after flushing Magento Cache
- Fixed logic in L2 Cache model
1 parent ac0c588 commit 8873703

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function __construct(array $options = [])
135135
*/
136136
public function setDirectives($directives)
137137
{
138-
return $this->local->setDirectives($directives);
138+
$this->remote->setDirectives($directives);
139139
}
140140

141141
/**
@@ -250,6 +250,8 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
250250
$this->local->clean();
251251
}
252252

253+
// Local cache doesn't save tags intentionally since it will cause inconsistency after flushing the cache
254+
// in multinode environment
253255
return $this->local->save($dataToSave, $id, [], $specificLifetime);
254256
}
255257

@@ -260,17 +262,19 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
260262
*/
261263
private function checkIfLocalCacheSpaceExceeded()
262264
{
263-
return $this->getFillingPercentage() >= ($this->_options['cleanup_percentage'] ?? 95);
265+
return $this->local->getFillingPercentage() >= ($this->_options['cleanup_percentage'] ?? 95);
264266
}
265267

266268
/**
267269
* @inheritdoc
268270
*/
269271
public function remove($id)
270272
{
271-
return $this->removeRemoteDataVersion($id) &&
272-
$this->remote->remove($id) &&
273-
$this->local->remove($id);
273+
$result = $this->removeRemoteDataVersion($id) && $this->remote->remove($id);
274+
if ($result && !$this->_options['use_stale_cache']) {
275+
$result = $this->local->remove($id);
276+
}
277+
return $result;
274278
}
275279

276280
/**
@@ -279,79 +283,79 @@ public function remove($id)
279283
public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
280284
{
281285
return $this->remote->clean($mode, $tags) &&
282-
$this->local->clean($mode, $tags);
286+
$this->local->clean($mode);
283287
}
284288

285289
/**
286290
* @inheritdoc
287291
*/
288292
public function getIds()
289293
{
290-
return $this->local->getIds();
294+
return $this->remote->getIds();
291295
}
292296

293297
/**
294298
* @inheritdoc
295299
*/
296300
public function getTags()
297301
{
298-
return $this->local->getTags();
302+
return $this->remote->getTags();
299303
}
300304

301305
/**
302306
* @inheritdoc
303307
*/
304308
public function getIdsMatchingTags($tags = [])
305309
{
306-
return $this->local->getIdsMatchingTags($tags);
310+
return $this->remote->getIdsMatchingTags($tags);
307311
}
308312

309313
/**
310314
* @inheritdoc
311315
*/
312316
public function getIdsNotMatchingTags($tags = [])
313317
{
314-
return $this->local->getIdsNotMatchingTags($tags);
318+
return $this->remote->getIdsNotMatchingTags($tags);
315319
}
316320

317321
/**
318322
* @inheritdoc
319323
*/
320324
public function getIdsMatchingAnyTags($tags = [])
321325
{
322-
return $this->local->getIdsMatchingAnyTags($tags);
326+
return $this->remote->getIdsMatchingAnyTags($tags);
323327
}
324328

325329
/**
326330
* @inheritdoc
327331
*/
328332
public function getFillingPercentage()
329333
{
330-
return $this->local->getFillingPercentage();
334+
return $this->remote->getFillingPercentage();
331335
}
332336

333337
/**
334338
* @inheritdoc
335339
*/
336340
public function getMetadatas($id)
337341
{
338-
return $this->local->getMetadatas($id);
342+
return $this->remote->getMetadatas($id);
339343
}
340344

341345
/**
342346
* @inheritdoc
343347
*/
344348
public function touch($id, $extraLifetime)
345349
{
346-
return $this->local->touch($id, $extraLifetime);
350+
return $this->remote->touch($id, $extraLifetime);
347351
}
348352

349353
/**
350354
* @inheritdoc
351355
*/
352356
public function getCapabilities()
353357
{
354-
return $this->local->getCapabilities();
358+
return $this->remote->getCapabilities();
355359
}
356360

357361
/**

lib/internal/Magento/Framework/Cache/Test/Unit/Backend/RemoteSynchronizedCacheTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,21 @@ public function testRemove(): void
337337
*/
338338
public function testClean(): void
339339
{
340+
$mode = 'clean_tags';
341+
$tags = ['MAGE'];
340342
$this->remoteCacheMockExample
341343
->expects($this->exactly(1))
342344
->method('clean')
345+
->with($mode, $tags)
343346
->willReturn(true);
344347

345-
$this->remoteSyncCacheInstance->clean();
348+
$this->localCacheMockExample
349+
->expects($this->once())
350+
->method('clean')
351+
->with($mode, [])
352+
->willReturn(true);
353+
354+
$this->remoteSyncCacheInstance->clean($mode, $tags);
346355
}
347356

348357
/**
@@ -353,6 +362,7 @@ public function testClean(): void
353362
public function testSaveWithEqualRemoteData(): void
354363
{
355364
$remoteData = 1;
365+
$tags = ['MAGE'];
356366

357367
$this->remoteCacheMockExample
358368
->method('load')
@@ -361,9 +371,10 @@ public function testSaveWithEqualRemoteData(): void
361371
$this->localCacheMockExample
362372
->expects($this->once())
363373
->method('save')
374+
->with($remoteData, 1, [])
364375
->willReturn(true);
365376

366-
$this->remoteSyncCacheInstance->save($remoteData, 1);
377+
$this->remoteSyncCacheInstance->save($remoteData, 1, $tags);
367378
}
368379

369380
/**

0 commit comments

Comments
 (0)