File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -10,20 +10,29 @@ developed for high performance.
1010
1111Basic uses of the cache looks like this::
1212
13- if (!$cache->has('my_cache_key')) {
13+ use Symfony\Contracts\Cache\ItemInterface;
14+
15+ // The callable will only be executed on a cache miss.
16+ $value = $pool->get('my_cache_key', function (ItemInterface $item) {
17+ $item->expiresAfter(3600);
18+
1419 // ... do some HTTP request or heavy computations
15- $cache->set('my_cache_key', 'foobar', 3600);
16- }
20+ $computedValue = 'foobar';
1721
18- echo $cache->get('my_cache_key'); // 'foobar'
22+ return $computedValue;
23+ });
1924
20- // ... and to remove the cache key
21- $cache->delete('my_cache_key');
25+ echo $value; // 'foobar'
2226
27+ // ... and to remove the cache key
28+ $pool->delete('my_cache_key');
2329
2430Symfony supports PSR-6 and PSR-16 cache interfaces. You can read more about
2531these at the :doc: `component documentation </components/cache >`.
2632
33+ .. versionadded :: 4.2
34+
35+ The cache contracts were introduced in Symfony 4.2.
2736
2837Configuring Cache with FrameworkBundle
2938--------------------------------------
You can’t perform that action at this time.
0 commit comments