Skip to content

Commit 330490a

Browse files
committed
added kernel.cache_clearer tag to the ref
1 parent cd9eda4 commit 330490a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

reference/dic_tags.rst

+53
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ the AsseticBundle has several tags that aren't listed here.
2424
+-----------------------------------+---------------------------------------------------------------------------+
2525
| `form.type_guesser`_ | Add your own logic for "form type guessing" |
2626
+-----------------------------------+---------------------------------------------------------------------------+
27+
| `kernel.cache_clearer`_ | Register your service to be called during the cache clearing process |
28+
+-----------------------------------+---------------------------------------------------------------------------+
2729
| `kernel.cache_warmer`_ | Register your service to be called during the cache warming process |
2830
+-----------------------------------+---------------------------------------------------------------------------+
2931
| `kernel.event_listener`_ | Listen to different events/hooks in Symfony |
@@ -144,6 +146,57 @@ tag its service definition with ``form.type_guesser`` (it has no options).
144146
To see an example of how this class might look, see the ``ValidatorTypeGuesser``
145147
class in the ``Form`` component.
146148

149+
kernel.cache_clearer
150+
--------------------
151+
152+
**Purpose**: Register your service to be called during the cache clearing process
153+
154+
Cache clearing occurs whenever you call ``cache:clear`` command. If your
155+
bundle caches files, you should add custom cache clearer for clearing those
156+
files during the cache clearing process.
157+
158+
In order to register your custom cache clearer, first you must create a
159+
service class::
160+
161+
// src/Acme/MainBundle/Cache/MyClearer.php
162+
namespace Acme\MainBundle\Cache;
163+
164+
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
165+
166+
class MyClearer implements CacheClearerInterface
167+
{
168+
public function clear($cacheDir)
169+
{
170+
// clear your cache
171+
}
172+
173+
}
174+
175+
Then register this class and tag it with ``kernel.cache:clearer``:
176+
177+
.. configuration-block::
178+
179+
.. code-block:: yaml
180+
181+
services:
182+
my_cache_clearer:
183+
class: Acme\MainBundle\Cache\MyClearer
184+
tags:
185+
- { name: kernel.cache_clearer }
186+
187+
.. code-block:: xml
188+
189+
<service id="my_cache_clearer" class="Acme\MainBundle\Cache\MyClearer">
190+
<tag name="kernel.cache_clearer" />
191+
</service>
192+
193+
.. code-block:: php
194+
195+
$container
196+
->register('my_cache_clearer', 'Acme\MainBundle\Cache\MyClearer')
197+
->addTag('kernel.cache_clearer')
198+
;
199+
147200
kernel.cache_warmer
148201
-------------------
149202

0 commit comments

Comments
 (0)