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

Appearance settings

[Cache][Messenger] fixed CallbackInterface support in async expiration handler #49422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ function (CacheItem $item, float $startTime) {
$startTime = microtime(true);
$pool = $message->findPool($this->reverseContainer);
$callback = $message->findCallback($this->reverseContainer);
$value = $callback($item);
$save = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this implement the handling of this $save flag ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is at this point this is not needed since it was specifically asked to recalculate the cache item asynchronously.
There could be some use cases that I miss though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look like I am doing something wrong here. But I am also guessing if handling $save will make things worse for someone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas can you give your opinion on this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is at this point this is not needed since it was specifically asked to recalculate the cache item asynchronously.

Correct!

$value = $callback($item, $save);
$setMetadata($item, $startTime);
$pool->save($item->set($value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Symfony\Component\Cache\Tests\Messenger;

use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Messenger\EarlyExpirationHandler;
use Symfony\Component\Cache\Messenger\EarlyExpirationMessage;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ReverseContainer;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Contracts\Cache\CallbackInterface;

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

$computationService = new class() {
public function __invoke(CacheItem $item)
$computationService = new class() implements CallbackInterface {
public function __invoke(CacheItemInterface $item, bool &$save)
{
usleep(30000);
$item->expiresAfter(3600);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.