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 @@ -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 }
You can’t perform that action at this time.
0 commit comments