Skip to content

Navigation Menu

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 5fb9e7a

Browse filesBrowse files
[Cache] Fix invalidating on save failures with ArrayAdapter
1 parent 196c99e commit 5fb9e7a
Copy full SHA for 5fb9e7a

File tree

4 files changed

+18
-14
lines changed
Filter options

4 files changed

+18
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ private function freeze($value, string $key): string|int|float|bool|array|\UnitE
312312
try {
313313
$serialized = serialize($value);
314314
} catch (\Exception $e) {
315-
unset($this->values[$key], $this->expiries[$key], $this->tags[$key]);
316315
$type = get_debug_type($value);
317316
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
318317
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

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

357374
class NotUnserializable

‎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
@@ -102,17 +102,4 @@ public function testEnum()
102102

103103
$this->assertSame(TestEnum::Foo, $cache->getItem('foo')->get());
104104
}
105-
106-
public function testExpiryCleanupOnError()
107-
{
108-
$cache = new ArrayAdapter();
109-
110-
$item = $cache->getItem('foo');
111-
$this->assertTrue($cache->save($item->set('bar')));
112-
$this->assertTrue($cache->hasItem('foo'));
113-
114-
$item->set(static fn () => null);
115-
$this->assertFalse($cache->save($item));
116-
$this->assertFalse($cache->hasItem('foo'));
117-
}
118105
}

‎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.