File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments