Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)

// ...
}
Expand Down