Skip to content

Commit 12e2ef0

Browse files
committed
Merge pull request symfony#2608 from pvolok/cache_clearer_tag
Added kernel.cache_clearer tag to the reference
2 parents 9330ec2 + 330490a commit 12e2ef0

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
@@ -41,6 +41,8 @@ may also be tags in other bundles you use that aren't listed here.
4141
+-----------------------------------+---------------------------------------------------------------------------+
4242
| `form.type_guesser`_ | Add your own logic for "form type guessing" |
4343
+-----------------------------------+---------------------------------------------------------------------------+
44+
| `kernel.cache_clearer`_ | Register your service to be called during the cache clearing process |
45+
+-----------------------------------+---------------------------------------------------------------------------+
4446
| `kernel.cache_warmer`_ | Register your service to be called during the cache warming process |
4547
+-----------------------------------+---------------------------------------------------------------------------+
4648
| `kernel.event_listener`_ | Listen to different events/hooks in Symfony |
@@ -334,6 +336,57 @@ tag its service definition with ``form.type_guesser`` (it has no options).
334336
To see an example of how this class might look, see the ``ValidatorTypeGuesser``
335337
class in the ``Form`` component.
336338
339+
kernel.cache_clearer
340+
--------------------
341+
342+
**Purpose**: Register your service to be called during the cache clearing process
343+
344+
Cache clearing occurs whenever you call ``cache:clear`` command. If your
345+
bundle caches files, you should add custom cache clearer for clearing those
346+
files during the cache clearing process.
347+
348+
In order to register your custom cache clearer, first you must create a
349+
service class::
350+
351+
// src/Acme/MainBundle/Cache/MyClearer.php
352+
namespace Acme\MainBundle\Cache;
353+
354+
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
355+
356+
class MyClearer implements CacheClearerInterface
357+
{
358+
public function clear($cacheDir)
359+
{
360+
// clear your cache
361+
}
362+
363+
}
364+
365+
Then register this class and tag it with ``kernel.cache:clearer``:
366+
367+
.. configuration-block::
368+
369+
.. code-block:: yaml
370+
371+
services:
372+
my_cache_clearer:
373+
class: Acme\MainBundle\Cache\MyClearer
374+
tags:
375+
- { name: kernel.cache_clearer }
376+
377+
.. code-block:: xml
378+
379+
<service id="my_cache_clearer" class="Acme\MainBundle\Cache\MyClearer">
380+
<tag name="kernel.cache_clearer" />
381+
</service>
382+
383+
.. code-block:: php
384+
385+
$container
386+
->register('my_cache_clearer', 'Acme\MainBundle\Cache\MyClearer')
387+
->addTag('kernel.cache_clearer')
388+
;
389+
337390
kernel.cache_warmer
338391
-------------------
339392

0 commit comments

Comments
 (0)