summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Holywell <[email protected]>2014-06-22 01:15:19 +0100
committerSimon Holywell <[email protected]>2014-06-22 01:15:19 +0100
commitf27715f07c8784ad751321c876de23635aa19673 (patch)
treed386fd298dec6c4467cff80493b52881662b7819 /docs
parente7b77adc4378c9a7581d7793a7e6717cbadc10f8 (diff)
Tidy up the caching pull request
Diffstat (limited to 'docs')
-rw-r--r--docs/configuration.rst47
1 files changed, 25 insertions, 22 deletions
diff --git a/docs/configuration.rst b/docs/configuration.rst
index a93c91e..6b5f2ff 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -328,33 +328,36 @@ 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.
-
+
+Custom caching
+''''''''''''''
+
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;
- });
+ $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