8000 [Cache] skip storing failure-to-save as misses in ArrayAdapter · symfony/symfony@ba66987 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba66987

Browse files
[Cache] skip storing failure-to-save as misses in ArrayAdapter
1 parent 09fe733 commit ba66987

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function testGetValuesHitAndMiss()
4747
// Miss (should be present as NULL in $values)
4848
$cache->getItem('bar');
4949

50+
// Fail (should be missing from $values)
51+
$item = $cache->getItem('buz');
52+
$cache->save($item->set(function() {}));
53+
5054
$values = $cache->getValues();
5155

5256
$this->assertCount(2, $values);

src/Symfony/Component/Cache/Traits/ArrayTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private function freeze($value, $key)
145145
try {
146146
$serialized = serialize($value);
147147
} catch (\Exception $e) {
148+
unset($this->values[$key]);
148149
$type = \is_object($value) ? \get_class($value) : \gettype($value);
149150
$message = sprintf('Failed to save key "{key}" of type %s: ', $type).$e->getMessage();
150151
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);

0 commit comments

Comments
 (0)
0