Browse files

adjusting the changes and adding some docs

  • Loading branch information...
1 parent 00abe27 commit 83a11b7189b3789194552d807f3b59adf1e14712 @dogmatic69 dogmatic69 committed Feb 10, 2013
Showing with 26 additions and 24 deletions.
  1. +26 −24 lib/Cake/Model/Model.php
View
50 lib/Cake/Model/Model.php
@@ -2678,39 +2678,42 @@ public function hasAny($conditions = null) {
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
*/
public function find($type = 'first', $query = array()) {
- $query = $this->_beforeFind($type, $query);
+ $this->findQueryType = $type;
+ $this->id = $this->getID();
+
+ $query = $this->buildQuery($type, $query);
if (is_null($query)) {
return null;
}
- return $this->_afterFind($type, $query);
- }
-
-/**
- * Before running a find
- *
- * @param string $type the find type to run
- * @param array $query the finds query params
- *
- * @return array|null
- */
- protected function _beforeFind($type, $query) {
- $this->findQueryType = $type;
- $this->id = $this->getID();
-
- return $this->buildQuery($type, $query);
+ return $this->_readDataSource($type, $query);
}
/**
- * After running a find
+ * Read from the datasource
+ *
+ * Model::_readDataSource() is used by all find() calls to read from the data source and can be overloaded to allow
+ * caching of datasource calls.
*
- * @param string $type the find type to run
- * @param array $query the finds query params
- * @param array $results they results from the find
+ * {{{
+ * protected function _readDataSource($type, $query) {
+ * $cacheName = md5(json_encode($query));
+ * $cache = Cache::read($cacheName, 'cache-config-name');
+ * if ($cache !== false) {
+ * return $cache;
+ * }
+ *
+ * $results = parent::_readDataSource($type, $query);
+ * Cache::write($cacheName, $results, 'cache-config-name');
+ * return $results;
+ * }
+ * }}}
*
- * @return array|null
+ * @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
+ * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
+ * @return array
*/
- protected function _afterFind($type, $query) {
+ protected function _readDataSource($type, $query) {
$results = $this->getDataSource()->read($this, $query);
$this->resetAssociations();
@@ -2727,7 +2730,6 @@ protected function _afterFind($type, $query) {
if ($this->findMethods[$type] === true) {
return $this->{'_find' . ucfirst($type)}('after', $query, $results);
}
-
}
/**

0 comments on commit 83a11b7

Please sign in to comment.