Skip to content

Commit

Permalink
Tidy up the caching pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Jun 22, 2014
1 parent e7b77ad commit f27715f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ foreach ($tweets as $tweet) {
Changelog
---------

#### 1.5.0 - release 2014-01-XX
#### 1.5.0 - release 2014-06-XX

* Multiple OR'ed conditions support [[lrlopez](https://github.com/lrlopez)] - [issue #201](https://github.com/j4mie/idiorm/issues/201)
* `where_id_in()` for selecting multiple records by primary key [[lrlopez](https://github.com/lrlopez)] - [issue #202](https://github.com/j4mie/idiorm/issues/202)
* Add compound primary key support [[lrlopez](https://github.com/lrlopez)] - [issue #171](https://github.com/j4mie/idiorm/issues/171)
* Add a RAW JOIN source to the query [[moiseevigor](https://github.com/moiseevigor)] - [issue #163](https://github.com/j4mie/idiorm/issues/163)
* offsetExists() should return true for null values, resolves [#181](https://github.com/j4mie/idiorm/issues/181) [[cainmi](https://github.com/cainmi)] - [issue #214](https://github.com/j4mie/idiorm/pull/214)
* Custom cache callback functions [[peter-mw](https://github.com/peter-mw)] - [issue #216](https://github.com/j4mie/idiorm/pull/216)
* Restrict null primary keys on update/delete, resolves [#203](https://github.com/j4mie/idiorm/issues/203) [[cainmi](https://github.com/cainmi)] - [issue #205](https://github.com/j4mie/idiorm/issues/205)
* Ensure parameters treated by type correctly [[charsleysa](https://github.com/charsleysa)] & [[SneakyBobito](https://github.com/SneakyBobito)] - [issue #206](https://github.com/j4mie/idiorm/issues/206) & [issue #208](https://github.com/j4mie/idiorm/issues/208)
* Reduce the type casting on aggregate functions to allow characters [[herroffizier](https://github.com/herroffizier)] - [issue #150](https://github.com/j4mie/idiorm/issues/150)
Expand Down
47 changes: 25 additions & 22 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f27715f

Please sign in to comment.