Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

initial docs for cache integration #7

Merged
merged 2 commits into from

5 participants

@lsmith77

No description provided.

@lsmith77

i guess once doctrine/common-documentation#7 is merged we should link to it from these docs.

@pborreli

thank you @lsmith77 :+1:

Without this doc it was hard to figure out that you have to close the cursor in order to make the cache works.

Same for the need of fetching all the resultset. fetch didn't work => fetchAll worked.

@marijn marijn commented on the diff
en/reference/caching.rst
((36 lines not shown))
+
+In order for the data to actually be cached its necessary to ensure that the entire
+result set is read (easiest way to ensure this is to use ``fetchAll``) and the statement
+object is closed:
+
+::
+
+ <?php
+ $stmt = $conn->executeCachedQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
+ $data = $stmt->fetchAll();
+ $stmt->close() // at this point the result is cached
+
+
+.. warning::
+
+ When using the cache layer not all fetch modes are supported.
@marijn
marijn added a note

I guess most importantly, this should state which ones are and which ones are not.

feel free to send me a PR to add this information :)

@marijn
marijn added a note
@stof
stof added a note

@lsmith77 could you update this point before this PR is merged ?

i will leave that to a later time .. but i have added the above link to make it easier for people to find out ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@guilhermeblanco guilhermeblanco merged commit a3dc17d into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 23, 2012
  1. @lsmith77
Commits on Sep 27, 2012
  1. @lsmith77
This page is out of date. Refresh to see the latest.
Showing with 54 additions and 0 deletions.
  1. +1 −0  en/index.rst
  2. +53 −0 en/reference/caching.rst
View
1  en/index.rst
@@ -28,6 +28,7 @@ Contents:
reference/sharding_azure_tutorial
reference/supporting-other-databases
reference/portability
+ reference/caching
reference/known-vendor-issues
Indices and tables
View
53 en/reference/caching.rst
@@ -0,0 +1,53 @@
+Caching
+=======
+
+A ``Doctrine\DBAL\Statement`` can automatically cache result sets.
+
+For this to work an instance of ``Doctrine\Common\Cache\Cache`` 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();
+ $config = $conn->getConfiguration();
+ $config->setResultCacheImpl($cache);
+
+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``
+instance. The difference between these two methods is that the former does not
+require this instance, while the later has this instance as a required parameter:
+
+::
+
+ <?php
+ $stmt = $conn->executeQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
+ $stmt = $conn->executeCachedQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
+
+It is also possible to pass in a the ``Doctrine\Common\Cache\Cache`` 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__);
+ new QueryCacheProfile(0, "some key", $cache);
+
+In order for the data to actually be cached its necessary to ensure that the entire
+result set is read (easiest way to ensure this is to use ``fetchAll``) and the statement
+object is closed:
+
+::
+
+ <?php
+ $stmt = $conn->executeCachedQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
+ $data = $stmt->fetchAll();
+ $stmt->close() // at this point the result is cached
+
+
+.. warning::
+
+ When using the cache layer not all fetch modes are supported. See the code of the
@marijn
marijn added a note

I guess most importantly, this should state which ones are and which ones are not.

feel free to send me a PR to add this information :)

@marijn
marijn added a note
@stof
stof added a note

@lsmith77 could you update this point before this PR is merged ?

i will leave that to a later time .. but i have added the above link to make it easier for people to find out ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+`ResultCacheStatement
+<https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php#L156>`_ for details.
Something went wrong with that request. Please try again.