Skip to content

Commit 84dc154

Browse files
committed
Merge branch '6.4' into 7.3
* 6.4: [Cache] Wrong callable in async cache computation example
2 parents 5072de7 + 2b87932 commit 84dc154

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
@@ -865,11 +865,12 @@ First, create a service that will compute the item's value::
865865
// src/Cache/CacheComputation.php
866866
namespace App\Cache;
867867

868-
use Symfony\Contracts\Cache\ItemInterface;
868+
use Psr\Cache\CacheItemInterface;
869+
use Symfony\Contracts\Cache\CallbackInterface;
869870

870-
class CacheComputation
871+
class CacheComputation implements CallbackInterface
871872
{
872-
public function compute(ItemInterface $item): string
873+
public function __invoke(CacheItemInterface $item, bool &$save): string
873874
{
874875
$item->expiresAfter(5);
875876

@@ -893,10 +894,10 @@ In the following example, the value is requested from a controller::
893894
class CacheController extends AbstractController
894895
{
895896
#[Route('/cache', name: 'cache')]
896-
public function index(CacheInterface $asyncCache): Response
897+
public function index(CacheInterface $asyncCache, CacheComputation $cacheComputation): Response
897898
{
898899
// pass to the cache the service method that refreshes the item
899-
$cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute'])
900+
$cachedValue = $asyncCache->get('my_value', $cacheComputation)
900901

901902
// ...
902903
}

0 commit comments

Comments
 (0)