Skip to content

Navigation Menu

Sign in
Appearance settings

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 7e73e82

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

File tree

1 file changed

+75
-44
lines changed
Filter options

1 file changed

+75
-44
lines changed

‎cache.rst

Copy file name to clipboardExpand all lines: cache.rst
+75-44Lines changed: 75 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,81 @@ 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 mainly used by Symfony components for
148+
things like annotations, serializer, and validation. For advanced use-cases it
149+
is also available for application code under the following constraints:
150+
151+
- Entries are derived from source code and can be generated during cache warmup
152+
by a CacheWarmer
153+
- Cached content only needs to change if the source code also changes (i.e.
154+
only on deployment on non-development machines); it should be regarded as
155+
read-only after deployment
156+
157+
By default the system cache uses the special ``cache.adapter.system`` adapter
158+
which writes to the file system and chains the APCu adapter if APCu is
159+
available. In most cases the default adapter should be the right choice for
160+
your application.
161+
162+
The application cache ``cache.app`` can be used as a multi-purpose data cache
163+
in your application and bundle code. In general, data in this pool does not
164+
need to be flushed on deployment. It defaults to ``cache.adapter.filesystem``
165+
but it is recommended to configure another adapter like Redis if available, so
166+
that data both "survives" deployments and is available on multiple instances in
167+
a multi-server setup.
168+
Custom pools (see section below) will default to ``cache.app`` as adapter if
169+
not specified explicitly.
170+
When using autowiring in your service definitions, ``cache.app`` will by
171+
default be injected if a service argument declares ``CacheItemPoolInterface``,
172+
``AdapterInterface``, or ``CacheInterface`` as its type.
173+
174+
You can configure which adapter (template) these predefined pools use by using
175+
the ``app`` and ``system`` key like:
176+
177+
.. configuration-block::
178+
179+
.. code-block:: yaml
180+
181+
# config/packages/cache.yaml
182+
framework:
183+
cache:
184+
app: cache.adapter.filesystem
185+
system: cache.adapter.system
186+
187+
.. code-block:: xml
188+
189+
<!-- config/packages/cache.xml -->
190+
<?xml version="1.0" encoding="UTF-8" ?>
191+
<container xmlns="http://symfony.com/schema/dic/services"
192+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
193+
xmlns:framework="http://symfony.com/schema/dic/symfony"
194+
xsi:schemaLocation="http://symfony.com/schema/dic/services
195+
https://symfony.com/schema/dic/services/services-1.0.xsd
196+
http://symfony.com/schema/dic/symfony
197+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
198+
199+
<framework:config>
200+
<framework:cache app="cache.adapter.filesystem"
201+
system="cache.adapter.system"
202+
/>
203+
</framework:config>
204+
</container>
205+
206+
.. code-block:: php
207+
208+
// config/packages/cache.php
209+
$container->loadFromExtension('framework', [
210+
'cache' => [
211+
'app' => 'cache.adapter.filesystem',
212+
'system' => 'cache.adapter.system',
213+
],
214+
]);
215+
185216
Creating Custom (Namespaced) Pools
186217
----------------------------------
187218

0 commit comments

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