8000 Update Cache component doc for 4.2 · symfony/symfony-docs@e7b2bdf · GitHub
[go: up one dir, main page]

Skip to content

Commit e7b2bdf

Browse files
nicolas-grekasjaviereguiluz
authored andcommitted
Update Cache component doc for 4.2
1 parent 50bbacc commit e7b2bdf

File tree

1 file changed

+39
-92
lines changed

1 file changed

+39
-92
lines changed

components/cache.rst

Lines changed: 39 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
The Cache Component
99
===================
1010

11-
The Cache component provides an extended `PSR-6`_ implementation as well as
12-
a `PSR-16`_ "Simple Cache" implementation for adding cache to your applications.
13-
It is designed for performance and resiliency, and ships with ready to use
14-
adapters for the most common caching backends, including proxies for adapting
15-
from/to `Doctrine Cache`_.
11+
The Cache component provides features covering simple to advanced caching needs.
12+
It natively implements `PSR-6`_ and the `Cache Contract`_ for greatest
13+
interoperability. It is designed for performance and resiliency, ships with
14+
ready to use adapters for the most common caching backends, including proxies for
15+
adapting from/to `Doctrine Cache`_ and `PSR-16`_. It enables tag-based invalidation
16+
and cache stampede protection.
1617

1718
Installation
1819
------------
@@ -23,112 +24,58 @@ Installation
2324
2425
.. include:: /components/require_autoload.rst.inc
2526

26-
Cache (PSR-6) Versus Simple Cache (PSR-16)
27-
------------------------------------------
27+
Cache Contracts versus PSR-6
28+
----------------------------
2829

2930
This component includes *two* different approaches to caching:
3031

3132
:ref:`PSR-6 Caching <cache-component-psr6-caching>`:
32-
A fully-featured cache system, which includes cache "pools", more advanced
33-
cache "items", and :ref:`cache tagging for invalidation <cache-component-tags>`.
33+
A generic cache system, which involves cache "pools" and cache "items".
3434

35-
:ref:`PSR-16 Simple Caching <cache-component-psr16-caching>`:
36-
A simple way to store, fetch and remove items from a cache.
37-
38-
Both methods support the *same* cache adapters and will give you very similar performance.
35+
:ref:`Cache Contracts <cache-component-contracts>`:
36+
A simple yet powerful way to store, fetch and remove values from a cache.
3937

4038
.. tip::
4139

42-
The component also contains adapters to convert between PSR-6 and PSR-16 caches.
43-
See :doc:`/components/cache/psr6_psr16_adapters`.
44-
45-
.. _cache-component-psr16-caching:
46-
47-
Simple Caching (PSR-16)
48-
-----------------------
49-
50-
This part of the component is an implementation of `PSR-16`_, which means that its
51-
basic API is the same as defined in the standard. First, create a cache object from
52-
one of the built-in cache classes. For example, to create a filesystem-based cache,
53-
instantiate :class:`Symfony\\Component\\Cache\\Simple\\FilesystemCache`::
54-
55-
use Symfony\Component\Cache\Simple\FilesystemCache;
56-
57-
$cache = new FilesystemCache();
40+
Using the Cache Contracts approach is recommended: using it requires less
41+
code boilerplate and provides cache stampede protection by default.
5842

59-
Now you can create, retrieve, update and delete items using this object::
60-
61-
// save a new item in the cache
62-
$cache->set('stats.products_count', 4711);
63-
64-
// or set it with a custom ttl
65-
// $cache->set('stats.products_count', 4711, 3600);
66-
67-
// retrieve the cache item
68-
if (!$cache->has('stats.products_count')) {
69-
// ... item does not exists in the cache
70-
}
71-
72-
// retrieve the value stored by the item
73-
$productsCount = $cache->get('stats.products_count');
74-
75-
// or specify a default value, if the key doesn't exist
76-
// $productsCount = $cache->get('stats.products_count', 100);
77-
78-
// remove the cache key
79-
$cache->delete('stats.products_count');
80-
81-
// clear *all* cache keys
82-
$cache->clear();
83-
84-
You can also work with multiple items at once::
85-
86-
$cache->setMultiple([
87-
'stats.products_count' => 4711,
88-
'stats.users_count' => 1356,
89-
]);
90-
91-
$stats = $cache->getMultiple([
92-
'stats.products_count',
93-
'stats.users_count',
94-
]);
43+
.. tip::
9544

96-
$cache->deleteMultiple([
97-
'stats.products_count',
98-
'stats.users_count',
99-
]);
45+
The component also contains adapters to convert between PSR-6, PSR-16 and
46+
Doctrine caches. See :doc:`/components/cache/psr6_psr16_adapters` and
47+
:doc:`/components/cache/adapters/doctrine_adapter`.
10048

101-
Available Simple Cache (PSR-16) Classes
102-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
Available Cache Adapters
50+
~~~~~~~~~~~~~~~~~~~~~~~~
10351

10452
The following cache adapters are available:
10553

10654
.. tip::
10755

10856
To find out more about each of these classes, you can read the
109-
:doc:`PSR-6 Cache Pool </components/cache/cache_pools>` page. These "Simple"
110-
(PSR-16) cache classes aren't identical to the PSR-6 Adapters on that page, but
111-
each share constructor arguments and use-cases.
112-
113-
* :class:`Symfony\\Component\\Cache\\Simple\\ApcuCache`
114-
* :class:`Symfony\\Component\\Cache\\Simple\\ArrayCache`
115-
* :class:`Symfony\\Component\\Cache\\Simple\\ChainCache`
116-
* :class:`Symfony\\Component\\Cache\\Simple\\DoctrineCache`
117-
* :class:`Symfony\\Component\\Cache\\Simple\\FilesystemCache`
118-
* :class:`Symfony\\Component\\Cache\\Simple\\MemcachedCache`
119-
* :class:`Symfony\\Component\\Cache\\Simple\\NullCache`
120-
* :class:`Symfony\\Component\\Cache\\Simple\\PdoCache`
121-
* :class:`Symfony\\Component\\Cache\\Simple\\PhpArrayCache`
122-
* :class:`Symfony\\Component\\Cache\\Simple\\PhpFilesCache`
123-
* :class:`Symfony\\Component\\Cache\\Simple\\RedisCache`
124-
* :class:`Symfony\\Component\\Cache\\Simple\\TraceableCache`
57+
:doc:`PSR-6 Cache Pool </components/cache/cache_pools>` page.
58+
59+
* :class:`Symfony\\Component\\Cache\\Adapter\\ApcuAdapter`
60+
* :class:`Symfony\\Component\\Cache\\Adapter\\ArrayAdapter`
61+
* :class:`Symfony\\Component\\Cache\\Adapter\\ChainAdapter`
62+
* :class:`Symfony\\Component\\Cache\\Adapter\\DoctrineAdapter`
63+
* :class:`Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter`
64+
* :class:`Symfony\\Component\\Cache\\Adapter\\MemcachedAdapter`
65+
* :class:`Symfony\\Component\\Cache\\Adapter\\NullAdapter`
66+
* :class:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter`
67+
* :class:`Symfony\\Component\\Cache\\Adapter\\PhpArrayAdapter`
68+
* :class:`Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter`
69+
* :class:`Symfony\\Component\\Cache\\Adapter\\RedisAdapter`
70+
* :class:`Symfony\\Component\\Cache\\Adapter\\SimpleCacheAdapter`
71+
* :class:`Symfony\\Component\\Cache\\Adapter\\TraceableAdapter`
12572

12673
.. _cache-component-psr6-caching:
12774

128-
More Advanced Caching (PSR-6)
129-
-----------------------------
75+
More Generic Caching (PSR-6)
76+
----------------------------
13077

131-
To use the more-advanced, PSR-6 Caching abilities, you'll need to learn its key
78+
To use the more-generic, PSR-6 Caching abilities, you'll need to learn its key
13279
concepts:
13380

13481
**Item**
@@ -177,8 +124,8 @@ Now you can create, retrieve, update and delete items using this cache pool::
177124

178125
For a list of all of the supported adapters, see :doc:`/components/cache/cache_pools`.
179126

180-
Advanced Usage (PSR-6)
181-
----------------------
127+
Advanced Usage
128+
--------------
182129

183130
.. toctree::
184131
:glob:

0 commit comments

Comments
 (0)
0