8000 [Serializer] Remove `CacheableSupportsMethodInterface` · symfony/symfony-docs@7b9f807 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b9f807

Browse files
alexandre-dauboisjaviereguiluz
authored andcommitted
[Serializer] Remove CacheableSupportsMethodInterface
1 parent e38e587 commit 7b9f807

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

serializer/custom_normalizer.rst

+5-36
7142
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,19 @@ a service and :doc:`tagged </service_container/tags>` with ``serializer.normaliz
6363
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
6464
this is done automatically!
6565

66-
Performance
67-
-----------
66+
Performance of Normalizers/Denormalizers
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6868

6969
To figure which normalizer (or denormalizer) must be used to handle an object,
7070
the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
7171
:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization`
7272
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
7373
of all registered normalizers (or denormalizers) in a loop.
7474

75-
The result of these methods can vary depending on the object to serialize, the
76-
format and the context. That's why the result **is not cached** by default and
77-
can result in a significant performance bottleneck.
78-
79-
However, most normalizers (and denormalizers) always return the same result when
80-
the object's type and the format are the same, so the result can be cached. To
81-
do so, make those normalizers (and denormalizers) implement the
82-
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
83-
and return ``true`` when
84-
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
85-
is called.
86-
87-
.. note::
88-
89-
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
90-
as well the ones included in `API Platform`_ natively implement this interface.
91-
92-
.. deprecated:: 6.3
93-
94-
The :class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
95-
interface is deprecated since Symfony 6.3. You should implement the
96-
``getSupportedTypes()`` method instead, as shown in the section below.
97-
98-
Improving Performance of Normalizers/Denormalizers
99-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100-
101-
.. versionadded:: 6.3
102-
103-
The ``getSupportedTypes()`` method was introduced in Symfony 6.3.
104-
105-
Both :class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface`
75+
Additionally, both
76+
:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface`
10677
and :class:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface`
107-
contain a new method ``getSupportedTypes()``. This method allows normalizers or
78+
contain the ``getSupportedTypes()`` method. This method allows normalizers or
10879
denormalizers to declare the type of objects they can handle, and whether they
10980
are cacheable. With this info, even if the ``supports*()`` call is not cacheable,
11081
the Serializer can skip a ton of method calls to ``supports*()`` improving
@@ -148,5 +119,3 @@ Here is an example of how to use the ``getSupportedTypes()`` method::
148119

149120
Note that ``supports*()`` method implementations should not assume that
150121
``getSupportedTypes()`` has been called before.
151-
152-
.. _`API Platform`: https://api-platform.com

0 commit comments

Comments
 (0)
0