Skip to content

Commit 10f8326

Browse files
committed
Some rewords
1 parent c85eff1 commit 10f8326

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

components/cache.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,23 @@ This component includes *two* different approaches to caching:
5353
Cache Contracts
5454
---------------
5555

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::
5963

6064
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
6165

6266
$cache = new FilesystemAdapter();
6367

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::
6573

6674
use Symfony\Contracts\Cache\ItemInterface;
6775

@@ -82,7 +90,7 @@ Now you can retrieve and delete cached data using this object::
8290

8391
.. note::
8492

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
8694
:doc:`/components/cache/cache_invalidation`.
8795

8896
The Cache Contracts also comes with built in `Stampede prevention`_. This will
@@ -96,8 +104,12 @@ prevention
96104

97105
The solution is to recompute the value before the cache expires. The algorithm
98106
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::
101113

102114
use Symfony\Contracts\Cache\ItemInterface;
103115

0 commit comments

Comments
 (0)