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 @@ -865,11 +865,12 @@ First, create a service that will compute the item's value::
865865 // src/Cache/CacheComputation.php
866866 namespace App\Cache;
867867
868- use Symfony\Contracts\Cache\ItemInterface;
868+ use Psr\Cache\CacheItemInterface;
869+ use Symfony\Contracts\Cache\CallbackInterface;
869870
870- class CacheComputation
871+ class CacheComputation implements CallbackInterface
871872 {
872- public function compute(ItemInterface $item): string
873+ public function __invoke(CacheItemInterface $item, bool &$save ): string
873874 {
874875 $item->expiresAfter(5);
875876
@@ -893,10 +894,10 @@ In the following example, the value is requested from a controller::
893894 class CacheController extends AbstractController
894895 {
895896 #[Route('/cache', name: 'cache')]
896- public function index(CacheInterface $asyncCache): Response
897+ public function index(CacheInterface $asyncCache, CacheComputation $cacheComputation ): Response
897898 {
898899 // pass to the cache the service method that refreshes the item
899- $cachedValue = $asyncCache->get('my_value', [CacheComputation::class, 'compute'] )
900+ $cachedValue = $asyncCache->get('my_value', $cacheComputation )
900901
901902 // ...
902903 }
You can’t perform that action at this time.
0 commit comments