Skip to content

Commit

Permalink
Minor reword
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Sep 12, 2018
1 parent 8d6ca70 commit 3e2e30f
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions components/serializer.rst
Expand Up @@ -1304,23 +1304,22 @@ the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
of all registered normalizers (or denormalizers) in a loop.

The result of these methods can vary depending of the value of the object to serialize, of the format to
use, and of the context. Consequently, **it is not cached** by default.

Because they are called recursively, these methods are usually a huge performance bottleneck. Moreover, most
normalizers (and denormalizers) always return the same result when the object's type, and the format are
the same.

To hint the serializer that it's safe to cache the result of these methods (and then dramatically improve the
overall performance), such normalizers (and denormalizers) should implement the
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface` and return ``true`` when
The result of these methods can vary depending on the object to serialize, the
format and the context. That's why the result **is not cached** by default and
can result in a significant performance bottleneck.

However, most normalizers (and denormalizers) always return the same result when
the object's type and the format are the same, so the result can be cached. To
do so, make those normalizers (and denormalizers) implement the
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
and return ``true`` when
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
is called.

.. note::

Built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`, as well the ones
included in `API Platform`_ natively implement this interface.
.. note::
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
as well the ones included in `API Platform`_ natively implement this interface.

Learn more
----------
Expand Down

0 comments on commit 3e2e30f

Please sign in to comment.