Skip to content

[Cache] Adding about marshallers #15054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ Now you can create, retrieve, update and delete items using this cache pool::

For a list of all of the supported adapters, see :doc:`/components/cache/cache_pools`.

Serializing Data
----------------

When an item is stored in the cache, it is serialised to a string. It is a class
implementing :class:`Symfony\\Component\\Cache\\Marshaller\\MarshallerInterface`
that is responsible for serializing and unserializing. Or to be technically correct:
to ``marshall()`` and to ``unmarshall()``.

The :class:`Symfony\\Component\\Cache\\Marshaller\\DefaultMarshaller` is using PHP's
``serialize()`` or ``igbinary_serialize()`` if the Igbinary extension is installed.
There are other marshallers that will encrypt or compress the data before storing it::

use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\DefaultMarshaller;
use Symfony\Component\Cache\DeflateMarshaller;

$marshaller = new DeflateMarshaller(new DefaultMarshaller());
$cache = new RedisAdapter(new \Redis(), 'namespace', 0, $marshaller);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add the way to do it framework side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this docs. This is for the component only.


Advanced Usage
--------------

Expand Down