Skip to content

Commit ee7c851

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [Cache] Split PdoAdapter to DoctrineDbalAdapter
2 parents b073443 + 86f4e93 commit ee7c851

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

components/cache/adapters/pdo_doctrine_dbal_adapter.rst

Lines changed: 49 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
@@ -40,13 +50,43 @@ your code.
4050
.. tip::
4151

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

4584
.. note::
4685

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.
86+
DBAL Connection are lazy-loaded by default; some additional options may be
87+
necessary to detect the database engine and version without opening the
88+
connection.
5089

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

0 commit comments

Comments
 (0)