Skip to content

Commit b3bc0c3

Browse files
[Cache] Fix calling the callback wrapper for ChainAdapter
1 parent a923e6c commit b3bc0c3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/Cache/Adapter/ChainAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
106106
$callback = $wrap;
107107
$beta = \INF === $beta ? \INF : 0;
108108
}
109-
if ($adapter instanceof CacheInterface) {
109+
if ($adapter instanceof CacheInterface && $i !== $this->adapterCount) {
110110
$value = $adapter->get($key, $callback, $beta, $metadata);
111111
} else {
112112
$value = $this->doGet($adapter, $key, $callback, $beta, $metadata);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,28 @@ private function getNonPruneableMock(): AdapterInterface
266266
{
267267
return $this->createMock(AdapterInterface::class);
268268
}
269+
270+
public function testSetCallbackWrapperPropagation()
271+
{
272+
$adapter1 = new ArrayAdapter();
273+
$adapter2 = new FilesystemAdapter();
274+
275+
$chain = new ChainAdapter([$adapter1, $adapter2]);
276+
277+
$callbackWrapperCalled = false;
278+
$customWrapper = static function (callable $callback, CacheItem $item, bool &$save) use (&$callbackWrapperCalled) {
279+
$callbackWrapperCalled = true;
280+
281+
return $callback($item, $save);
282+
};
283+
284+
$chain->setCallbackWrapper($customWrapper);
285+
286+
$chain->delete('test-callback-wrapper');
287+
288+
$result = $chain->get('test-callback-wrapper', static fn () => 'computed-value');
289+
290+
$this->assertTrue($callbackWrapperCalled);
291+
$this->assertSame('computed-value', $result);
292+
}
269293
}

0 commit comments

Comments
 (0)