Skip to content

Commit

Permalink
Document PSR-6 caching
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed May 14, 2021
1 parent e026b54 commit 5062a68
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/en/reference/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ Caching

A ``Doctrine\DBAL\Statement`` can automatically cache result sets.

For this to work an instance of ``Doctrine\Common\Cache\Cache`` must be provided.
For this to work an instance of ``Psr\Cache\CacheItemPoolInterface`` must be provided.
This can be set on the configuration object (optionally it can also be passed at query time):

::

<?php
$cache = new \Doctrine\Common\Cache\ArrayCache();
$cache = new \Symfony\Component\Cache\Adapter\ArrayAdapter();
$config = $conn->getConfiguration();
$config->setResultCacheImpl($cache);
$config->setResultCache($cache);

Note that this documentation uses Symfony Cache in all examples. Any other cache implementation
that follows the PSR-6 standard can be used instead.

To get the result set of a query cached it is necessary to pass a
``Doctrine\DBAL\Cache\QueryCacheProfile`` instance to the ``executeQuery`` or ``executeCacheQuery``
Expand All @@ -24,14 +27,14 @@ require this instance, while the later has this instance as a required parameter
$stmt = $conn->executeQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
$stmt = $conn->executeCacheQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));

It is also possible to pass in a ``Doctrine\Common\Cache\Cache`` instance into the
It is also possible to pass in a ``Psr\Cache\CacheItemPoolInterface`` instance into the
constructor of ``Doctrine\DBAL\Cache\QueryCacheProfile`` in which case it overrides
the default cache instance:

::

<?php
$cache = new \Doctrine\Common\Cache\FilesystemCache(__DIR__);
$cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
new QueryCacheProfile(0, "some key", $cache);

In order for the data to actually be cached its necessary to ensure that the entire
Expand Down

0 comments on commit 5062a68

Please sign in to comment.