[Solar-svn] Revision 3166
pmjones at solarphp.com
pmjones at solarphp.com
Sat May 17 17:09:15 CDT 2008
Solar_Sql_Model: [ADD] Method countPages() now honors the 'cache' param.
Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php 2008-05-17 13:07:27 UTC (rev 3165)
+++ trunk/Solar/Sql/Model.php 2008-05-17 22:09:14 UTC (rev 3166)
@@ -1122,7 +1122,7 @@
// attempt to fetch from database, and add to the cache
$result = $select->fetch($type);
- // add to cache? (use 'add' to avoid race conditions.)
+ // add to cache?
if ($params['cache']) {
$this->_cache->add($key, $result);
}
@@ -1194,6 +1194,20 @@
// fix up the parameters
$params = $this->fixSelectParams($params);
+ // add a fake param called 'count' to make this different from the
+ // orginating query (for cache deconfliction).
+ $params['__count__'] = true;
+
+ // check the cache
+ if ($params['cache']) {
+ $key = $this->_cache->entry($params);
+ $result = $this->_cache->fetch($key);
+ if ($result !== false) {
+ // cache hit
+ return $result;
+ }
+ }
+
// remove the 'eager' param for now, so we don't get the column-
// based eager joins.
$eager = (array) $params['eager'];
@@ -1208,9 +1222,17 @@
$related->modSelectCountPages($select);
}
- // done, count on the primary column
+ // count on the primary column
$col = "{$this->_model_name}.{$this->_primary_col}";
- return $select->countPages($col);
+ $result = $select->countPages($col);
+
+ // save in cache?
+ if ($params['cache']) {
+ $this->_cache->add($key, $result);
+ }
+
+ // done
+ return $result;
}
/**
More information about the Solar-svn
mailing list