From dcd2a1230fb3954baae3546bf377ef795fddbb22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20B=C3=B6lsterli?= Date: Mon, 24 Nov 2025 13:06:12 +0100 Subject: [PATCH] [Cache] Wrong callable in async cache computation example --- cache.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cache.rst b/cache.rst index 71fe56c2b33..4a919695350 100644 --- a/cache.rst +++ b/cache.rst @@ -888,11 +888,12 @@ First, create a service that will compute the item's value:: // src/Cache/CacheComputation.php namespace App\Cache; - use Symfony\Contracts\Cache\ItemInterface; + use Psr\Cache\CacheItemInterface; + use Symfony\Contracts\Cache\CallbackInterface; - class CacheComputation + class CacheComputation implements CallbackInterface { - public function compute(ItemInterface $item): string + public function __invoke(CacheItemInterface $item, bool &$save): string { $item->expiresAfter(5); @@ -916,10 +917,10 @@ In the following example, the value is requested from a controller:: class CacheController extends AbstractController { #[Route('/cache', name: 'cache')] - public function index(CacheInterface $asyncCache): Response + public function index(CacheInterface $asyncCache, CacheComputation $cacheComputation): Response { // pass to the cache the service method that refreshes the item - $cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute']) + $cachedValue = $asyncCache->get('my_value', $cacheComputation) // ... }