Skip to content

Commit ba1b327

Browse files
committed
MC-33275: Stale cache implementation
1 parent 819d3d1 commit ba1b327

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,39 +198,28 @@ private function removeRemoteDataVersion($id)
198198
public function load($id, $doNotTestCacheValidity = false)
199199
{
200200
$localData = $this->local->load($id);
201-
$remoteData = false;
202-
$versionCheckFailed = false;
203201

204-
if (false === $localData) {
205-
$remoteData = $this->remote->load($id);
206-
207-
if (false === $remoteData) {
208-
return false;
209-
}
210-
} else {
211-
if ($versionCheckFailed = ($this->getDataVersion($localData) !== $this->loadRemoteDataVersion($id))) {
212-
$remoteData = $this->remote->load($id);
213-
214-
if (!$this->_options['use_stale_cache']) {
215-
$localData = false;
216-
}
202+
if ($localData) {
203+
if ($this->getDataVersion($localData) === $this->loadRemoteDataVersion($id)) {
204+
return $localData;
217205
}
218206
}
219207

220-
if ($remoteData !== false) {
208+
$remoteData = $this->remote->load($id);
209+
if ($remoteData) {
221210
$this->local->save($remoteData, $id);
222-
$localData = $remoteData;
223-
} elseif ($this->_options['use_stale_cache'] && $localData !== false && $versionCheckFailed) {
211+
212+
return $remoteData;
213+
} elseif ($localData && $this->_options['use_stale_cache']) {
224214
if ($this->lock($id)) {
225215
return false;
226216
} else {
227-
$this->notifier = $this->notifier ??
228-
ObjectManager::getInstance()->get(CompositeStaleCacheNotifier::class);
229-
$this->notifier->cacheLoaderIsUsingStaleCache();
217+
$this->notifyStaleCache();
218+
return $localData;
230219
}
231220
}
232221

233-
return $localData;
222+
return false;
234223
}
235224

236225
/**
@@ -424,7 +413,7 @@ private function getLockName($id): string
424413
*/
425414
private function unlockAll()
426415
{
427-
foreach ($this->lockList as $id => $ttl) {
416+
foreach ($this->lockList as $id) {
428417
$this->unlock($id);
429418
}
430419
}
@@ -461,4 +450,11 @@ private function generateLockSign()
461450

462451
return $sign;
463452
}
453+
454+
private function notifyStaleCache(): void
455+
{
456+
$this->notifier = $this->notifier ??
457+
ObjectManager::getInstance()->get(CompositeStaleCacheNotifier::class);
458+
$this->notifier->cacheLoaderIsUsingStaleCache();
459+
}
464460
}

setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Setup\Model\ConfigOptionsList;
89

setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Setup\Test\Unit\Model\ConfigOptionsList;
99

1010
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\Setup\Option\FlagConfigOption;
1112
use Magento\Framework\Setup\Option\SelectConfigOption;
1213
use Magento\Framework\Setup\Option\TextConfigOption;
1314
use Magento\Setup\Model\ConfigOptionsList\Cache as CacheConfigOptionsList;
@@ -48,7 +49,7 @@ protected function setUp(): void
4849
public function testGetOptions()
4950
{
5051
$options = $this->configOptionsList->getOptions();
51-
$this->assertCount(8, $options);
52+
$this->assertCount(9, $options);
5253

5354
$this->assertArrayHasKey(0, $options);
5455
$this->assertInstanceOf(SelectConfigOption::class, $options[0]);
@@ -81,6 +82,10 @@ public function testGetOptions()
8182
$this->assertArrayHasKey(7, $options);
8283
$this->assertInstanceOf(TextConfigOption::class, $options[7]);
8384
$this->assertEquals('cache-id-prefix', $options[7]->getName());
85+
86+
$this->assertArrayHasKey(8, $options);
87+
$this->assertInstanceOf(FlagConfigOption::class, $options[8]);
88+
$this->assertEquals('allow-parallel-generation', $options[8]->getName());
8489
}
8590

8691
/**
@@ -105,11 +110,13 @@ public function testCreateConfigCacheRedis()
105110
],
106111
'id_prefix' => $this->expectedIdPrefix(),
107112
]
108-
]
113+
],
114+
'allow_parallel_generation' => '',
109115
]
110116
];
111117

112-
$configData = $this->configOptionsList->createConfig(['cache-backend'=>'redis'], $this->deploymentConfigMock);
118+
$configData = $this->configOptionsList
119+
->createConfig(['cache-backend' => 'redis'], $this->deploymentConfigMock);
113120

114121
$this->assertEquals($expectedConfigData, $configData->getData());
115122
}
@@ -134,7 +141,8 @@ public function testCreateConfigWithRedisConfig()
134141
],
135142
'id_prefix' => $this->expectedIdPrefix(),
136143
]
137-
]
144+
],
145+
'allow_parallel_generation' => null,
138146
]
139147
];
140148

@@ -211,7 +219,7 @@ public function testValidateWithValidInput()
211219
];
212220
$this->validatorMock->expects($this->once())
213221
->method('isValidConnection')
214-
->with(['host'=>'localhost', 'db'=>'', 'port'=>'', 'password'=>''])
222+
->with(['host' => 'localhost', 'db' => '', 'port' => '', 'password' => ''])
215223
->willReturn(true);
216224

217225
$errors = $this->configOptionsList->validate($options, $this->deploymentConfigMock);

0 commit comments

Comments
 (0)