Skip to content

Commit dcd2a12

Browse files
mboelsterlijaviereguiluz
authored andcommitted
[Cache] Wrong callable in async cache computation example
1 parent 643bc71 commit dcd2a12

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)