summaryrefslogtreecommitdiff
path: root/docs/configuration.rst
diff options
context:
space:
mode:
authorPeter Ivanov <[email protected]>2014-06-20 15:19:47 +0300
committerSimon Holywell <[email protected]>2014-06-22 01:03:11 +0100
commite7b77adc4378c9a7581d7793a7e6717cbadc10f8 (patch)
tree91561424fb6b0a10a45b70c323df01d4cc4c3beb /docs/configuration.rst
parent00c6f6cce5f31c239c217a3a21e4ba96e9b1fc91 (diff)
Added custom caching functions
This is a combination of 20 commits: added cache callback #212 added test Added text for custom cache formating and tests added caching_auto_clear option moved custom cache test for php 5.3+ fixed ConfigTest.php tabs to spaces formating formating added `create_cache_key` callback option added $table_name to clear cache function added $table_name to _create_cache_key added missing params added $table_name to cache_query_result formating tabs added $table_name to check_query_cache unify cache parameters order `table_name` is more important than `connection_name` formating
Diffstat (limited to 'docs/configuration.rst')
-rw-r--r--docs/configuration.rst43
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/configuration.rst b/docs/configuration.rst
index dba0c8c..a93c91e 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -287,6 +287,21 @@ Idiorm can cache the queries it executes during a request. To enable
query caching, set the ``caching`` option to ``true`` (it is ``false``
by default).
+.. code-block:: php
+
+ <?php
+ ORM::configure('caching', true);
+
+
+Setting: ``caching_auto_clear``
+
+Idiorm's cache is never cleared by default. If you wish to automatically clear it on save, set ``caching_auto_clear`` to ``true``
+
+.. code-block:: php
+
+ <?php
+ ORM::configure('caching_auto_clear', true);
+
When query caching is enabled, Idiorm will cache the results of every
``SELECT`` query it executes. If Idiorm encounters a query that has
already been run, it will fetch the results directly from its cache and
@@ -313,6 +328,34 @@ Warnings and gotchas
application, as all database rows that are fetched during each
request are held in memory. If you are working with large quantities
of data, you may wish to disable the cache.
+
+If you wish to use custom caching functions, you can set them from the configure options.
+
+.. code-block:: php
+
+ <?php
+ $my_cache = array();
+ ORM::configure('cache_query_result', function ($cache_key, $value, $table_name, $connection_name) use (&$my_cache) {
+ $my_cache[$cache_key] = $value;
+ });
+ ORM::configure('check_query_cache', function ($cache_key, $table_name, $connection_name) use (&$my_cache) {
+ if(isset($my_cache[$cache_key])){
+ return $my_cache[$cache_key];
+ } else {
+ return false;
+ }
+ });
+ ORM::configure('clear_cache', function ($table_name, $connection_name) use (&$my_cache) {
+ $my_cache = array();
+ });
+
+ ORM::configure('create_cache_key', function ($query, $parameters, $table_name, $connection_name) {
+ $parameter_string = join(',', $parameters);
+ $key = $query . ':' . $parameter_string;
+ $my_key = 'my-prefix'.crc32($key);
+ return $my_key;
+ });
+
.. _PDO documentation: http://php.net/manual/en/pdo.construct.php
.. _the PDO documentation: http://www.php.net/manual/en/pdo.construct.php