Skip to content

Async cache wrong callback example #20874

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

Open
torchello opened this issue Apr 10, 2025 · 3 comments
Open

Async cache wrong callback example #20874

torchello opened this issue Apr 10, 2025 · 3 comments

Comments

@torchello
Copy link

Hey! Seems like an example of a callback in async cache section is incorrect:

$cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute'])

It's not a valid callback as the compute method is not static in the example:

class CacheComputation
{
    public function compute(ItemInterface $item): string
    {
        ...
    }
}

Am I missing something or we should adjust the docs?

@torchello
Copy link
Author

Actually, some info from this page could be added to the docs. Wdyt?
https://symfony.com/blog/new-in-symfony-5-2-async-cache-recomputing

@torchello
Copy link
Author

Also, seems like

early_expiration_message_bus: messenger.default_bus

should be

early_expiration_message_bus: messenger.bus.default

@nicolas-grekas
Copy link
Member

About the callback: the callable can be a pseudo-callable, where the "object" on which the method is called is actually its service name. So the doc should work. There's something called EarlyExpirationDispatcher which will turn the string into the corresponding service.

About messenger.default_bus vsmessenger.bus.default, both should work.

Did you give all this a try?

PR welcome of course!

@nicolas-grekas nicolas-grekas removed their assignment May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants