Skip to content

Commit 9dd09fa

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: [Cache] Adding about marshallers
2 parents 5625491 + 90ce1b2 commit 9dd09fa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

components/cache.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ Now you can create, retrieve, update and delete items using this cache pool::
192192

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

195+
Marshalling (Serializing) Data
196+
------------------------------
197+
198+
.. note::
199+
200+
`Marshalling`_ and `serializing`_ are similar concepts. Serializing is the
201+
process of translating an object state into a format that can be stored
202+
(e.g. in a file). Marshalling is the process of translating both the object
203+
state and its codebase into a format that can be stored or transmitted.
204+
205+
Unmarshalling an object produces a copy of the original object, possibly by
206+
automatically loading the class definitions of the object.
207+
208+
Symfony uses *marshallers* (classes which implement
209+
:class:`Symfony\\Component\\Cache\\Marshaller\\MarshallerInterface`) to process
210+
the cache items before storing them.
211+
212+
The :class:`Symfony\\Component\\Cache\\Marshaller\\DefaultMarshaller` uses PHP's
213+
``serialize()`` or ``igbinary_serialize()`` if the `Igbinary extension`_ is installed.
214+
There are other *marshallers* that can encrypt or compress the data before storing it::
215+
216+
use Symfony\Component\Cache\Adapter\RedisAdapter;
217+
use Symfony\Component\Cache\DefaultMarshaller;
218+
use Symfony\Component\Cache\DeflateMarshaller;
219+
220+
$marshaller = new DeflateMarshaller(new DefaultMarshaller());
221+
$cache = new RedisAdapter(new \Redis(), 'namespace', 0, $marshaller);
222+
195223
Advanced Usage
196224
--------------
197225

@@ -205,3 +233,6 @@ Advanced Usage
205233
.. _`Cache Contracts`: https://github.com/symfony/contracts/blob/master/Cache/CacheInterface.php
206234
.. _`Stampede prevention`: https://en.wikipedia.org/wiki/Cache_stampede
207235
.. _Probabilistic early expiration: https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration
236+
.. _`Marshalling`: https://en.wikipedia.org/wiki/Marshalling_(computer_science)
237+
.. _`serializing`: https://en.wikipedia.org/wiki/Serialization
238+
.. _`Igbinary extension`: https://github.com/igbinary/igbinary

0 commit comments

Comments
 (0)