Skip to content

Commit 47d9be2

Browse files
committed
Merge branch '8.0' into 8.1
* 8.0: [Cache] Wrong callable in async cache computation example
2 parents a04c596 + c6ca90d commit 47d9be2

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

621-
use Symfony\Contracts\Cache\ItemInterface;
621+
use Psr\Cache\CacheItemInterface;
622+
use Symfony\Contracts\Cache\CallbackInterface;
622623

623-
class CacheComputation
624+
class CacheComputation implements CallbackInterface
624625
{
625-
public function compute(ItemInterface $item): string
626+
public function __invoke(CacheItemInterface $item, bool &$save): string
626627
{
627628
$item->expiresAfter(5);
628629

@@ -646,10 +647,10 @@ In the following example, the value is requested from a controller::
646647
class CacheController extends AbstractController
647648
{
648649
#[Route('/cache', name: 'cache')]
649-
public function index(CacheInterface $asyncCache): Response
650+
public function index(CacheInterface $asyncCache, CacheComputation $cacheComputation): Response
650651
{
651652
// pass to the cache the service method that refreshes the item
652-
$cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute'])
653+
$cachedValue = $asyncCache->get('my_value', $cacheComputation)
653654

654655
// ...
655656
}

0 commit comments

Comments
 (0)