@@ -53,15 +53,23 @@ This component includes *two* different approaches to caching:
53
53
Cache Contracts
54
54
---------------
55
55
56
- All adapters supports the Cache Contract. It contains only two methods; ``get `` and
57
- ``delete ``. The first thing you need is to instantiate a cache adapter. The
58
- :class: `Symfony\\ Component\\ Cache\\ Simple\\ FilesystemCache ` is used in this example::
56
+ All adapters supports the Cache Contract. It contains only two methods:
57
+ ``get() `` and ``delete() ``. There's no ``set() `` method because the ``get() ``
58
+ method both gets and sets the cache values.
59
+
60
+ The first thing you need is to instantiate a cache adapter. The
61
+ :class: `Symfony\\ Component\\ Cache\\ Simple\\ FilesystemCache ` is used in this
62
+ example::
59
63
60
64
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
61
65
62
66
$cache = new FilesystemAdapter();
63
67
64
- Now you can retrieve and delete cached data using this object::
68
+ Now you can retrieve and delete cached data using this object. The first
69
+ argument of the ``get() `` method is a key, an arbitrary string that you
70
+ associate to the cached value so you can retrieve it later. The second argument
71
+ is a PHP callable which is executed to generate the value (and store it in the
72
+ cache) when it's not found in the cache::
65
73
66
74
use Symfony\Contracts\Cache\ItemInterface;
67
75
@@ -82,7 +90,7 @@ Now you can retrieve and delete cached data using this object::
82
90
83
91
.. note ::
84
92
85
- Use tags to clear more than one key at the time. Read more at
93
+ Use cache tags to delete more than one key at the time. Read more at
86
94
:doc: `/components/cache/cache_invalidation `.
87
95
88
96
The Cache Contracts also comes with built in `Stampede prevention `_. This will
@@ -96,8 +104,12 @@ prevention
96
104
97
105
The solution is to recompute the value before the cache expires. The algorithm
98
106
randomly fakes a cache miss for one user while others still is served the cached
99
- value. The third parameter to ``CacheInterface::get `` is a beta value. The default
100
- is ``1.0 `` which works well in practice. A higher value means earlier recompute.::
107
+ value. You can control its behavior with the third optional parameter of
108
+ ``CacheInterface::get() ``, which is a float value called "beta".
109
+
110
+ By default the beta is ``1.0 `` and higher values mean earlier recompute. Set it
111
+ to ``0 `` to disable the recompute and set it to ``INF `` to trigger an immediate
112
+ recompute::
101
113
102
114
use Symfony\Contracts\Cache\ItemInterface;
103
115
0 commit comments