Skip to content

Async cache wrong callback example #20874

Open
@torchello

Description

@torchello

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?

Activity

torchello

torchello commented on Apr 10, 2025

@torchello
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

torchello commented on Apr 11, 2025

@torchello
Author

Also, seems like

early_expiration_message_bus: messenger.default_bus

should be

early_expiration_message_bus: messenger.bus.default
added this to the 6.4 milestone on May 23, 2025
nicolas-grekas

nicolas-grekas commented on May 23, 2025

@nicolas-grekas
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!

removed their assignment
on May 23, 2025
torchello

torchello commented on Jun 25, 2025

@torchello
Author

I could only make it working with:

messenger.bus.default

and

class CacheComputer implements CallbackInterface

I will double check again and will post the error messages I'm getting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @javiereguiluz@nicolas-grekas@torchello@OskarStark

        Issue actions

          Async cache wrong callback example · Issue #20874 · symfony/symfony-docs