Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit196c99e

Browse files
bug#60122 [Cache] ArrayAdapter serialization exception clean $expiries (bastien-wink)
This PR was submitted for the 7.3 branch but it was merged into the 6.4 branch instead.Discussion----------[Cache] ArrayAdapter serialization exception clean $expiries| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#60121| License | MITIn [ArrayAdapter.php:339](https://github.com/symfony/symfony/blame/7.3/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php#L339), if $value contains a Closure, an Exception is triggered and $this->values get cleaned.``` try { $serialized = serialize($value); } catch (\Exception $e) { unset($this->values[$key], $this->expiries[$key], $this->tags[$key]); $type = get_debug_type($value); $message = \sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage()); CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]); return null; }```$this->expiries is used in [ArrayAdapter.php:300](https://github.com/symfony/symfony/blame/7.3/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php#L300) to determine cache hit. If hash is found in $this->expiries but missing in $this->keys it generate a NOTICE.On serialize($value); catch Exception, clean expiries with unset.Commits-------91331e1 Add testsa4bfce3 bug#60121[Cache] ArrayAdapter serialization exception clean $expiries
2 parents31135c7 +91331e1 commit196c99e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ 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->tags[$key]);
315+
unset($this->values[$key],$this->expiries[$key],$this->tags[$key]);
316316
$type =get_debug_type($value);
317317
$message =sprintf('Failed to save key "{key}" of type %s: %s',$type,$e->getMessage());
318318
CacheItem::log($this->logger,$message, ['key' =>$key,'exception' =>$e,'cache-adapter' =>get_debug_type($this)]);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,17 @@ public function testEnum()
102102

103103
$this->assertSame(TestEnum::Foo,$cache->getItem('foo')->get());
104104
}
105+
106+
publicfunctiontestExpiryCleanupOnError()
107+
{
108+
$cache =newArrayAdapter();
109+
110+
$item =$cache->getItem('foo');
111+
$this->assertTrue($cache->save($item->set('bar')));
112+
$this->assertTrue($cache->hasItem('foo'));
113+
114+
$item->set(staticfn () =>null);
115+
$this->assertFalse($cache->save($item));
116+
$this->assertFalse($cache->hasItem('foo'));
117+
}
105118
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp