Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95e1748

Browse filesBrowse files
author
Stefan Kruppa
committed
Improve explanation of cache.app and cache.system
1 parent d54129d commit 95e1748
Copy full SHA for 95e1748

File tree

1 file changed

+65
-44
lines changed
Filter options

1 file changed

+65
-44
lines changed

‎cache.rst

Copy file name to clipboardExpand all lines: cache.rst
+65-44Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -52,50 +52,6 @@ of:
5252
Redis and Memcached are example of such adapters. If a DSN is used as the
5353
provider then a service is automatically created.
5454

55-
There are two pools that are always enabled by default. They are ``cache.app`` and
56-
``cache.system``. The system cache is used for things like annotations, serializer,
57-
and validation. The ``cache.app`` can be used in your code. You can configure which
58-
adapter (template) they use by using the ``app`` and ``system`` key like:
59-
60-
.. configuration-block::
61-
62-
.. code-block:: yaml
63-
64-
# config/packages/cache.yaml
65-
framework:
66-
cache:
67-
app: cache.adapter.filesystem
68-
system: cache.adapter.system
69-
70-
.. code-block:: xml
71-
72-
<!-- config/packages/cache.xml -->
73-
<?xml version="1.0" encoding="UTF-8" ?>
74-
<container xmlns="http://symfony.com/schema/dic/services"
75-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
76-
xmlns:framework="http://symfony.com/schema/dic/symfony"
77-
xsi:schemaLocation="http://symfony.com/schema/dic/services
78-
https://symfony.com/schema/dic/services/services-1.0.xsd
79-
http://symfony.com/schema/dic/symfony
80-
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
81-
82-
<framework:config>
83-
<framework:cache app="cache.adapter.filesystem"
84-
system="cache.adapter.system"
85-
/>
86-
</framework:config>
87-
</container>
88-
89-
.. code-block:: php
90-
91-
// config/packages/cache.php
92-
$container->loadFromExtension('framework', [
93-
'cache' => [
94-
'app' => 'cache.adapter.filesystem',
95-
'system' => 'cache.adapter.system',
96-
],
97-
]);
98-
9955
The Cache component comes with a series of adapters pre-configured:
10056

10157
* :doc:`cache.adapter.apcu </components/cache/adapters/apcu_adapter>`
@@ -182,6 +138,71 @@ will create pools with service IDs that follow the pattern ``cache.[type]``.
182138
],
183139
]);
184140
141+
System Cache and Application Cache
142+
----------------------------------
143+
144+
There are two pools that are always enabled by default. They are
145+
``cache.system`` and ``cache.app``.
146+
147+
The system cache ``cache.system`` is used for things like annotations,
148+
serializer, and validation. Usage is reserved for Symfony components
149+
and you should not use it for application cache needs.
150+
By default the system cache uses the special ``cache.adapter.system`` adapter
151+
which writes to the file system and chains the APCu adapter if APCu is
152+
available. In most cases the default adapter should be the right choice for
153+
your application. It will also be warmed when calling the ``cache:warmup``
154+
command.
155+
156+
The application cache ``cache.app`` can be used in your application and bundle
157+
code. It defaults to use ``cache.adapter.filesystem`` but may be reconfigured
158+
to fit your needs. Custom pools (see section below) will default to use
159+
``cache.app`` as adapter unless specified.
160+
When using autowiring in your service definitions, ``cache.app`` will by
161+
default be injected if a service argument declares ``CacheItemPoolInterface``,
162+
``AdapterInterface``, or ``CacheInterface`` as its type.
163+
164+
You can configure which adapter (template) these predefined pools use by using
165+
the ``app`` and ``system`` key like:
166+
167+
.. configuration-block::
168+
169+
.. code-block:: yaml
170+
171+
# config/packages/cache.yaml
172+
framework:
173+
cache:
174+
app: cache.adapter.filesystem
175+
system: cache.adapter.system
176+
177+
.. code-block:: xml
178+
179+
<!-- config/packages/cache.xml -->
180+
<?xml version="1.0" encoding="UTF-8" ?>
181+
<container xmlns="http://symfony.com/schema/dic/services"
182+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
183+
xmlns:framework="http://symfony.com/schema/dic/symfony"
184+
xsi:schemaLocation="http://symfony.com/schema/dic/services
185+
https://symfony.com/schema/dic/services/services-1.0.xsd
186+
http://symfony.com/schema/dic/symfony
187+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
188+
189+
<framework:config>
190+
<framework:cache app="cache.adapter.filesystem"
191+
system="cache.adapter.system"
192+
/>
193+
</framework:config>
194+
</container>
195+
196+
.. code-block:: php
197+
198+
// config/packages/cache.php
199+
$container->loadFromExtension('framework', [
200+
'cache' => [
201+
'app' => 'cache.adapter.filesystem',
202+
'system' => 'cache.adapter.system',
203+
],
204+
]);
205+
185206
Creating Custom (Namespaced) Pools
186207
----------------------------------
187208

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.