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
@@ -40,13 +50,43 @@ your code.
40
50
.. tip ::
41
51
42
52
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
+ );
44
83
45
84
.. note ::
46
85
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 .
50
89
51
90
.. _`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
52
92
.. _`Data Source Name (DSN)` : https://en.wikipedia.org/wiki/Data_source_name
0 commit comments