<commit_before>.. _symfony httpcache configuration:

Symfony HttpCache Configuration
-------------------------------

The ``symfony/http-kernel`` component provides a reverse proxy implemented
completely in PHP, called `HttpCache`_. While it is certainly less efficient
than using Varnish or NGINX, it can still provide considerable performance
gains over an installation that is not cached at all. It can be useful for
running an application on shared hosting for instance.

You can use features of this library with the help of the
``EventDispatchingHttpCache`` provided here. The basic concept is to use event
subscribers on the HttpCache class.

.. note::

    If you are using the full stack Symfony framework, have a look at the
    HttpCache provided by the FOSHttpCacheBundle_ instead.

.. warning::

    Symfony HttpCache does not currently provide support for banning.

Extending the Correct HttpCache Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Instead of extending ``Symfony\Component\HttpKernel\HttpCache\HttpCache``, your
``AppCache`` should extend ``FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache``.

.. tip::

    If your class already needs to extend a different class, simply copy the
    event handling code from the EventDispatchingHttpCache into your
    ``AppCache`` class. The drawback is that you need to manually check whether
    you need to adjust your ``AppCache`` each time you update the FOSHttpCache
    library.

Now that you have an event dispatching kernel, you can make it register the
subscribers you need. While you could do that from your bootstrap code, this is
not the recommended way. You would need to adjust every place you instantiate
the cache. Instead, overwrite the constructor of AppCache and register the
subscribers there. A simple cache will look like this::
<commit_msg>Make note about bundle for symfony httpcache a warning. fix #164<commit_after>.. _symfony httpcache configuration:

Symfony HttpCache Configuration
-------------------------------

The ``symfony/http-kernel`` component provides a reverse proxy implemented
completely in PHP, called `HttpCache`_. While it is certainly less efficient
than using Varnish or NGINX, it can still provide considerable performance
gains over an installation that is not cached at all. It can be useful for
running an application on shared hosting for instance.

You can use features of this library with the help of the
``EventDispatchingHttpCache`` provided here. The basic concept is to use event
subscribers on the HttpCache class.

.. warning::

    If you are using the full stack Symfony framework, have a look at the
    HttpCache provided by the FOSHttpCacheBundle_ instead.

.. note::

    Symfony HttpCache does not currently provide support for banning.

Extending the Correct HttpCache Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Instead of extending ``Symfony\Component\HttpKernel\HttpCache\HttpCache``, your
``AppCache`` should extend ``FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache``.

.. tip::

    If your class already needs to extend a different class, simply copy the
    event handling code from the EventDispatchingHttpCache into your
    ``AppCache`` class. The drawback is that you need to manually check whether
    you need to adjust your ``AppCache`` each time you update the FOSHttpCache
    library.

Now that you have an event dispatching kernel, you can make it register the
subscribers you need. While you could do that from your bootstrap code, this is
not the recommended way. You would need to adjust every place you instantiate
the cache. Instead, overwrite the constructor of AppCache and register the
subscribers there. A simple cache will look like this::

{'fraction_non_alphanumeric': 0.08088433540037746, 'fraction_numerical': 0.0008088433540037746, 'mean_word_length': 4.196078431372549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4105157', 'n_tokens_mistral': 896, 'n_tokens_neox': 868, 'n_words': 490}