Skip to content

Commit 8010f57

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Minor tweaks [Cache] Split PdoAdapter to DoctrineDbalAdapter
2 parents be1a2d0 + 041b040 commit 8010f57

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

components/cache/adapters/pdo_doctrine_dbal_adapter.rst

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@
77
PDO & Doctrine DBAL Cache Adapter
88
=================================
99

10-
This adapter stores the cache items in an SQL database. It requires a :phpclass:`PDO`,
11-
`Doctrine DBAL Connection`_, or `Data Source Name (DSN)`_ as its first parameter, and
12-
optionally a namespace, default cache lifetime, and options array as its second,
13-
third, and forth parameters::
10+
The PDO and Doctrine DBAL adapters store the cache items in a table of an SQL database.
11+
12+
.. note::
13+
14+
These adapters implement :class:`Symfony\\Component\\Cache\\PruneableInterface`,
15+
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>`
16+
by calling the ``prune()`` method.
17+
18+
Using PHP PDO
19+
-------------
20+
21+
The :class:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter` requires a :phpclass:`PDO`,
22+
or `Data Source Name (DSN)`_ as its first parameter. You can pass a namespace,
23+
default cache lifetime, and options array as the other optional arguments::
1424

1525
use Symfony\Component\Cache\Adapter\PdoAdapter;
1626

1727
$cache = new PdoAdapter(
1828

19-
// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
29+
// a PDO connection or DSN for lazy connecting through PDO
2030
$databaseConnectionOrDSN,
2131

2232
// the string prefixed to the keys of the items stored in this cache
@@ -37,16 +47,53 @@ You can also create this table explicitly by calling the
3747
:method:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter::createTable` method in
3848
your code.
3949

50+
.. deprecated:: 5.4
51+
52+
Using :class:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter` with a
53+
:class:`Doctrine\\DBAL\\Connection` or a DBAL URL is deprecated since Symfony 5.4
54+
and will be removed in Symfony 6.0.
55+
Use :class:`Symfony\\Component\\Cache\\Adapter\\DoctrineDbalAdapter` instead.
56+
4057
.. tip::
4158

4259
When passed a `Data Source Name (DSN)`_ string (instead of a database connection
43-
class instance), the connection will be lazy-loaded when needed.
60+
class instance), the connection will be lazy-loaded when needed. DBAL Connection
61+
are lazy-loaded by default; some additional options may be necessary to detect
62+
the database engine and version without opening the connection.
63+
64+
Using Doctrine DBAL
65+
-------------------
66+
67+
The :class:`Symfony\\Component\\Cache\\Adapter\\DoctrineDbalAdapter` requires a
68+
`Doctrine DBAL Connection`_, or `Doctrine DBAL URL`_ as its first parameter.
69+
You can pass a namespace, default cache lifetime, and options array as the other
70+
optional arguments::
71+
72+
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
73+
74+
$cache = new DoctrineDbalAdapter(
75+
76+
// a Doctrine DBAL connection or DBAL URL
77+
$databaseConnectionOrURL,
78+
79+
// the string prefixed to the keys of the items stored in this cache
80+
$namespace = '',
81+
82+
// the default lifetime (in seconds) for cache items that do not define their
83+
// own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
84+
// until the database table is truncated or its rows are otherwise deleted)
85+
$defaultLifetime = 0,
86+
87+
// an array of options for configuring the database table and connection
88+
$options = []
89+
);
4490

4591
.. note::
4692

47-
This adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
48-
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
49-
calling its ``prune()`` method.
93+
DBAL Connection are lazy-loaded by default; some additional options may be
94+
necessary to detect the database engine and version without opening the
95+
connection.
5096

5197
.. _`Doctrine DBAL Connection`: https://github.com/doctrine/dbal/blob/master/src/Connection.php
98+
.. _`Doctrine DBAL URL`: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
5299
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name

0 commit comments

Comments
 (0)