8000 bug #40655 [Cache] skip storing failure-to-save as misses in ArrayAda… · jderusse/symfony@2ceb35a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ceb35a

Browse files
committed
bug symfony#40655 [Cache] skip storing failure-to-save as misses in ArrayAdapter (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [Cache] skip storing failure-to-save as misses in ArrayAdapter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#38694 | License | MIT | Doc PR | - In addition to symfony#40645 Commits ------- ba66987 [Cache] skip storing failure-to-save as misses in ArrayAdapter
2 parents e16be83 + ba66987 commit 2ceb35a

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