7
7
PDO & Doctrine DBAL Cache Adapter
8
8
=================================
9
9
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::
14
24
15
25
use Symfony\Component\Cache\Adapter\PdoAdapter;
16
26
17
27
$cache = new PdoAdapter(
18
28
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
20
30
$databaseConnectionOrDSN,
21
31
22
32
// 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
37
47
:method: `Symfony\\ Component\\ Cache\\ Adapter\\ PdoAdapter::createTable ` method in
38
48
your code.
39
49
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
+
40
57
.. tip ::
41
58
42
59
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
+ );
44
90
45
91
.. note ::
46
92
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 .
50
96
51
97
.. _`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
52
99
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
0 commit comments