Allow to use URL DSN in PDO adapters

Jérémy Derussé
Contributed by Jérémy Derussé in #34057

The PDO cache adapter allows to configure the connection in several ways: using a PHP PDO object, a Doctrine DBAL Connection, or a Data Source Name (DSN). In Symfony 4.4, it will also be possible to use a URL DSN. This means for example that you can reuse the DATABASE_URL value if you want to:

1
2
3
4
5
6
7
8
9
10
11
12
13
# config/packages/cache.yaml
framework:
    cache:
        pools:
            cache.app:
                adapter: cache.adapter.pdo
                provider: app.my_pdo_provider

services:
    app.my_pdo_provider:
        factory: ['Symfony\Component\Cache\Adapter\PdoAdapter', 'createConnection']
        arguments:
            - '%env(DATABASE_URL)%'

Added new marshallers

Nicolas Grekas
Contributed by Nicolas Grekas in #33939 and #34133

In computing science, a marshaller transforms the memory representation of an object to a data format suitable for storage or transmission. In Symfony 4.4 we've added two marshallers to the Cache component.

The first one is TagAwareMarshaller, which optimizes the data storage when using tag-aware cache adapters. This marshaller is enabled automatically so you don't have to do anything.

The second one is DeflateMarshaller, which compresses the contents before caching them to save space (and uncompresses them automatically later, so the entire process is transparent to the user).

This marshaller is not enabled by default because that might break cache pools that are shared between different applications. You can enable it via decoration:

1
2
3
4
5
# config/services.yaml
services:
    Symfony\Component\Cache\Marshaller\DeflateMarshaller:
        decorates: cache.default_marshaller
        arguments: ['@Symfony\Component\Cache\Marshaller\DeflateMarshaller.inner']

Faster deletion of cache items

Nicolas Grekas
Contributed by Nicolas Grekas in #33921

Filesystem based cache adapters use a nested directory structure to store their contents. In Symfony 4.4, we introduced some optimizations to navigate that directory structure much faster when deleting items.

A Blackfire profiling showed a massive performance improvement (up to 100%) thanks to the removal of thousands of function calls related to RecursiveDirectoryIterator.

Simpler configuration of chained cache pools

Nicolas Grekas
Contributed by Nicolas Grekas in #32294

In Symfony 4.4, defining chained cache pools will be much simpler:

1
2
3
4
5
6
7
8
9
10
# config/packages/cache.yaml
framework:
    cache:
        pools:
            my_chained_pool:
                default_lifetime: 12
                adapters:
                  - cache.adapter.array
                  - cache.adapter.filesystem
                  - { name: cache.adapter.redis, provider: 'redis://foo' }
Published in #Living on the edge