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.
10
10
11
11
Basic uses of the cache looks like this::
12
12
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
+
14
19
// ... do some HTTP request or heavy computations
15
- $cache->set('my_cache_key', 'foobar', 3600);
16
- }
20
+ $computedValue = 'foobar';
17
21
18
- echo $cache->get('my_cache_key'); // 'foobar'
22
+ return $computedValue;
23
+ });
19
24
20
- // ... and to remove the cache key
21
- $cache->delete('my_cache_key');
25
+ echo $value; // 'foobar'
22
26
27
+ // ... and to remove the cache key
28
+ $pool->delete('my_cache_key');
23
29
24
30
Symfony supports PSR-6 and PSR-16 cache interfaces. You can read more about
25
31
these at the :doc: `component documentation </components/cache >`.
26
32
33
+ .. versionadded :: 4.2
34
+
35
+ The cache contracts were introduced in Symfony 4.2.
27
36
28
37
Configuring Cache with FrameworkBundle
29
38
--------------------------------------
You can’t perform that action at this time.
0 commit comments