Skip to content

Commit 2b87932

Browse files
committed
minor #21594 [Cache] Wrong callable in async cache computation example (mboelsterli)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Cache] Wrong callable in async cache computation example Already mentioned in #21587, but now with fix in 6.4 Branch with a reversible service. I've noticed the fix for closures in early-expiration callbacks: symfony/symfony#62398 in 6.4 and 7.4 (RC2) which fixed my issue in the dev environment: #21587 (comment) Commits ------- dcd2a12 [Cache] Wrong callable in async cache computation example
2 parents 491e435 + dcd2a12 commit 2b87932

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cache.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -888,11 +888,12 @@ First, create a service that will compute the item's value::
888888
// src/Cache/CacheComputation.php
889889
namespace App\Cache;
890890

891-
use Symfony\Contracts\Cache\ItemInterface;
891+
use Psr\Cache\CacheItemInterface;
892+
use Symfony\Contracts\Cache\CallbackInterface;
892893

893-
class CacheComputation
894+
class CacheComputation implements CallbackInterface
894895
{
895-
public function compute(ItemInterface $item): string
896+
public function __invoke(CacheItemInterface $item, bool &$save): string
896897
{
897898
$item->expiresAfter(5);
898899

@@ -916,10 +917,10 @@ In the following example, the value is requested from a controller::
916917
class CacheController extends AbstractController
917918
{
918919
#[Route('/cache', name: 'cache')]
919-
public function index(CacheInterface $asyncCache): Response
920+
public function index(CacheInterface $asyncCache, CacheComputation $cacheComputation): Response
920921
{
921922
// pass to the cache the service method that refreshes the item
922-
$cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute'])
923+
$cachedValue = $asyncCache->get('my_value', $cacheComputation)
923924

924925
// ...
925926
}

0 commit comments

Comments
 (0)