8000 bug #49422 [Cache][Messenger] fixed CallbackInterface support in asyn… · symfony/symfony@e9bd2ab · GitHub
[go: up one dir, main page]

Skip to content

Commit e9bd2ab

Browse files
bug #49422 [Cache][Messenger] fixed CallbackInterface support in async expiration handler (AdamKatzDev)
This PR was merged into the 5.4 branch. Discussion ---------- [Cache][Messenger] fixed CallbackInterface support in async expiration handler | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Adds support for CallbackInterface in EarlyExpirationHandler and thus fixes async cache recomputing for callables that implement CallbackInterface. Earlier similar errors were fixed in #31879. Commits ------- a8dea95 [Messenger][Cache] fixed CallbackInterface support in async expiration handler
2 parents eb9db6c + a8dea95 commit e9bd2ab

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Symfony/Component/Cache/Messenger/EarlyExpirationHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ function (CacheItem $item, float $startTime) {
7373
$startTime = microtime(true);
7474
$pool = $message->findPool($this->reverseContainer);
7575
$callback = $message->findCallback($this->reverseContainer);
76-
$value = $callback($item);
76+
$save = true;
77+
$value = $callback($item, $save);
7778
$setMetadata($item, $startTime);
7879
$pool->save($item->set($value));
7980
}

src/Symfony/Component/Cache/Tests/Messenger/EarlyExpirationHandlerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
namespace Symfony\Component\Cache\Tests\Messenger;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Cache\CacheItemInterface;
1516
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
16-
use Symfony\Component\Cache\CacheItem;
1717
use Symfony\Component\Cache\Messenger\EarlyExpirationHandler;
1818
use Symfony\Component\Cache\Messenger\EarlyExpirationMessage;
1919
use Symfony\Component\DependencyInjection\Container;
2020
use Symfony\Component\DependencyInjection\ReverseContainer;
2121
use Symfony\Component\DependencyInjection\ServiceLocator;
2222
use Symfony\Component\Filesystem\Filesystem;
23+
use Symfony\Contracts\Cache\CallbackInterface;
2324

2425
/**
2526
* @requires function Symfony\Component\DependencyInjection\ReverseContainer::__construct
@@ -40,8 +41,8 @@ public function testHandle()
4041
$item = $pool->getItem('foo');
4142
$item->set(234);
4243

43-
$computationService = new class() {
44-
public function __invoke(CacheItem $item)
44+
$computationService = new class() implements CallbackInterface {
45+
public function __invoke(CacheItemInterface $item, bool &$save)
4546
{
4647
usleep(30000);
4748
$item->expiresAfter(3600);

0 commit comments

Comments
 (0)
0