Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Cache] Split PdoAdapter to DoctrineDbalAdapter#15903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:5.4fromGromNaN:dbal/cache-pdo-5.4
Dec 27, 2021
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletionscomponents/cache/adapters/pdo_doctrine_dbal_adapter.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,16 +7,26 @@
PDO & Doctrine DBAL Cache Adapter
=================================

This adapter stores the cache items in an SQL database. It requires a :phpclass:`PDO`,
`Doctrine DBAL Connection`_, or `Data Source Name (DSN)`_ as its first parameter, and
optionally a namespace, default cache lifetime, and options array as its second,
third, and forth parameters::
The PDO and Doctrine DBAL adapters store the cache items in a table of an SQL database.

.. note::

Adapters implement :class:`Symfony\\Component\\Cache\\PruneableInterface`,
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
calling the ``prune()`` method.

Using :phpclass:`PDO`
---------------------

The :class:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter` requires a :phpclass:`PDO`,
or `Data Source Name (DSN)`_ as its first parameter, and optionally a namespace,
default cache lifetime, and options array as its second, third, and forth parameters::

use Symfony\Component\Cache\Adapter\PdoAdapter;

$cache = new PdoAdapter(

// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
// a PDO connection or DSN for lazy connecting through PDO
$databaseConnectionOrDSN,

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

.. deprecated:: 5.4

Using :class:`Symfony\\Component\\Cache\\Adapter\\PdoAdapter` with a
:class:`Doctrine\\DBAL\\Connection` or a DBAL URL is deprecated since Symfony 5.4
and will be removed in Symfony 6.0.
Use :class:`Symfony\\Component\\Cache\\Adapter\\DoctrineDbalAdapter` instead.

.. tip::

When passed a `Data Source Name (DSN)`_ string (instead of a database connection
class instance), the connection will be lazy-loaded when needed.
class instance), the connection will be lazy-loaded when needed. DBAL Connection
are lazy-loaded by default; some additional options may be necessary to detect
the database engine and version without opening the connection.


Using Doctrine DBAL
-------------------

The :class:`Symfony\\Component\\Cache\\Adapter\\DoctrineDbalAdapter` requires a
`Doctrine DBAL Connection`_, or `Doctrine DBAL URL`_ as its first parameter, and
optionally a namespace, default cache lifetime, and options array as its second,
third, and forth parameters::

use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;

$cache = new DoctrineDbalAdapter(

// a Doctrine DBAL connection or DBAL URL
$databaseConnectionOrURL,

// the string prefixed to the keys of the items stored in this cache
$namespace = '',

// the default lifetime (in seconds) for cache items that do not define their
// own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
// until the database table is truncated or its rows are otherwise deleted)
$defaultLifetime = 0,

// an array of options for configuring the database table and connection
$options = []
);

.. note::

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

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

[8]ページ先頭

©2009-2025 Movatter.jp