mirror of
https://github.com/symfony/symfony-docs.git
synced 2026-03-24 00:32:14 +01:00
[Cache] Wrong callable in async cache computation example
This commit is contained in:
committed by
Javier Eguiluz
parent
643bc71597
commit
dcd2a1230f
11
cache.rst
11
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)
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user