Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b44a51

Browse filesBrowse files
Merge branch '7.2' into 7.3
* 7.2: [Cache] Fix invalidating on save failures with Array|ApcuAdapter
2 parents 549126b + 7455c3c commit 8b44a51
Copy full SHA for 8b44a51

File tree

Expand file treeCollapse file tree

5 files changed

+25
-27
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+25
-27
lines changed

‎src/Symfony/Component/Cache/Adapter/ApcuAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,10 @@ protected function doSave(array $values, int $lifetime): array|bool
9898
return $failed;
9999
}
100100

101-
try {
102-
if (false === $failures = apcu_store($values, null, $lifetime)) {
103-
$failures = $values;
104-
}
105-
106-
return array_keys($failures);
107-
} catch (\Throwable $e) {
108-
if (1 === \count($values)) {
109-
// Workaround https://github.com/krakjoe/apcu/issues/170
110-
apcu_delete(array_key_first($values));
111-
}
112-
113-
throw $e;
101+
if (false === $failures = apcu_store($values, null, $lifetime)) {
102+
$failures = $values;
114103
}
104+
105+
return array_keys($failures);
115106
}
116107
}

‎src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ private function freeze($value, string $key): string|int|float|bool|array|\UnitE
338338
try {
339339
$serialized = serialize($value);
340340
} catch (\Exception $e) {
341-
unset($this->values[$key], $this->expiries[$key], $this->tags[$key]);
341+
if (!isset($this->expiries[$key])) {
342+
unset($this->values[$key]);
343+
}
342344
$type = get_debug_type($value);
343345
$message = \sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
344346
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);

‎src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ public function testNumericKeysWorkAfterMemoryLeakPrevention()
352352
$this->assertEquals('value-50', $cache->getItem((string) 50)->get());
353353
}
354354

355+
public function testErrorsDontInvalidate()
356+
{
357+
if (isset($this->skippedTests[__FUNCTION__])) {
358+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
359+
}
360+
361+
$cache = $this->createCachePool(0, __FUNCTION__);
362+
363+
$item = $cache->getItem('foo');
364+
$this->assertTrue($cache->save($item->set('bar')));
365+
$this->assertTrue($cache->hasItem('foo'));
366+
367+
$item->set(static fn () => null);
368+
$this->assertFalse($cache->save($item));
369+
$this->assertSame('bar', $cache->getItem('foo')->get());
370+
}
371+
355372
public function testNamespaces()
356373
{
357374
if (isset($this->skippedTests[__FUNCTION__])) {

‎src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php
-13Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ public function testEnum()
104104
$this->assertSame(TestEnum::Foo, $cache->getItem('foo')->get());
105105
}
106106

107-
public function testExpiryCleanupOnError()
108-
{
109-
$cache = new ArrayAdapter();
110-
111-
$item = $cache->getItem('foo');
112-
$this->assertTrue($cache->save($item->set('bar')));
113-
$this->assertTrue($cache->hasItem('foo'));
114-
115-
$item->set(static fn () => null);
116-
$this->assertFalse($cache->save($item));
117-
$this->assertFalse($cache->hasItem('foo'));
118-
}
119-
120107
public function testClockAware()
121108
{
122109
$clock = new MockClock();

‎src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PhpArrayAdapterTest extends AdapterTestCase
4242
'testSaveDeferredWhenChangingValues' => 'PhpArrayAdapter is read-only.',
4343
'testSaveDeferredOverwrite' => 'PhpArrayAdapter is read-only.',
4444
'testIsHitDeferred' => 'PhpArrayAdapter is read-only.',
45+
'testErrorsDontInvalidate' => 'PhpArrayAdapter is read-only.',
4546

4647
'testExpiresAt' => 'PhpArrayAdapter does not support expiration.',
4748
'testExpiresAtWithNull' => 'PhpArrayAdapter does not support expiration.',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.