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::
8000
td>
10
+ The PDO and Doctrine DBAL adapters store the cache items in a table of an SQL database.
11
+
12
+ .. note ::
13
+
14
+ Adapters implement :class: `Symfony\\ Component\\ Cache\\ PruneableInterface `,
15
+ allowing for manual :ref: `pruning of expired cache entries <component-cache-cache-pool-prune >` by
16
+ calling the ``prune() `` method.
17
+
18
+ Using :phpclass: `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, and optionally a namespace,
23
+ default cache lifetime, and options array as its second, third, and forth parameters::
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,54 @@ 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
+
65
+ Using Doctrine DBAL
66
+ -------------------
67
+
68
+ The :class: `Symfony\\ Component\\ Cache\\ Adapter\\ DoctrineDbalAdapter ` requires a
69
+ `Doctrine DBAL Connection `_, or `Doctrine DBAL URL `_ as its first parameter, and
70
+ optionally a namespace, default cache lifetime, and options array as its second,
71
+ third, and forth parameters::
72
+
73
+ use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
74
+
75
+ $cache = new DoctrineDbalAdapter(
76
+
77
+ // a Doctrine DBAL connection or DBAL URL
78
+ $databaseConnectionOrURL,
79
+
80
+ // the string prefixed to the keys of the items stored in this cache
81
+ $namespace = '',
82
+
83
+ // the default lifetime (in seconds) for cache items that do not define their
84
+ // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
85
+ // until the database table is truncated or its rows are otherwise deleted)
86
+ $defaultLifetime = 0,
87
+
88
+ // an array of options for configuring the database table and connection
89
+ $options = []
90
+ );
44
91
45
92
.. note ::
46
93
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 .
94
+ DBAL Connection are lazy-loaded by default; some additional options may be
95
+ necessary to detect the database engine and version without opening the
96
+ connection .
50
97
51
98
.. _`Doctrine DBAL Connection` : https://github.com/doctrine/dbal/blob/master/src/Connection.php
99
+ .. _`Doctrine DBAL URL` : https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
52
100
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
0 commit comments