caching docs
This commit is contained in:
parent
a5b31e9521
commit
2922c9aff6
@ -133,7 +133,7 @@ interface Doctrine_Adapter_Statement_Interface
|
|||||||
* bound parameters in the SQL statement being executed.
|
* bound parameters in the SQL statement being executed.
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
* @return boolean Returns TRUE on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
public function execute(array $params = array());
|
public function execute($params = null);
|
||||||
/**
|
/**
|
||||||
* fetch
|
* fetch
|
||||||
*
|
*
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
* and is licensed under the LGPL. For more information, see
|
* and is licensed under the LGPL. For more information, see
|
||||||
* <http://www.phpdoctrine.com>.
|
* <http://www.phpdoctrine.com>.
|
||||||
*/
|
*/
|
||||||
|
Doctrine::autoload('Doctrine_Db_EventListener');
|
||||||
/**
|
/**
|
||||||
* Doctrine_Cache
|
* Doctrine_Cache
|
||||||
*
|
*
|
||||||
@ -234,7 +235,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
|
|||||||
while ($i--) {
|
while ($i--) {
|
||||||
$element = next($stats);
|
$element = next($stats);
|
||||||
$query = key($stats);
|
$query = key($stats);
|
||||||
|
|
||||||
$hash = md5($query);
|
$hash = md5($query);
|
||||||
|
|
||||||
$this->_driver->delete($hash);
|
$this->_driver->delete($hash);
|
||||||
|
@ -428,7 +428,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
|
|||||||
|
|
||||||
if ( ! empty($params)) {
|
if ( ! empty($params)) {
|
||||||
$stmt = $this->dbh->prepare($statement);
|
$stmt = $this->dbh->prepare($statement);
|
||||||
|
|
||||||
return $stmt->execute($params);
|
return $stmt->execute($params);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ( ! $skip) {
|
if ( ! $skip) {
|
||||||
$stmt = $this->dbh->query($statement);
|
$stmt = $this->dbh->query($statement);
|
||||||
|
@ -52,7 +52,7 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
|
|||||||
}
|
}
|
||||||
public function getStatement()
|
public function getStatement()
|
||||||
{
|
{
|
||||||
return $this->stmt;
|
return $this->stmt;
|
||||||
}
|
}
|
||||||
public function getQuery()
|
public function getQuery()
|
||||||
{
|
{
|
||||||
@ -194,7 +194,7 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
|
|||||||
* bound parameters in the SQL statement being executed.
|
* bound parameters in the SQL statement being executed.
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
* @return boolean Returns TRUE on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
public function execute(array $params = array())
|
public function execute($params = null)
|
||||||
{
|
{
|
||||||
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->stmt->queryString, $params);
|
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->stmt->queryString, $params);
|
||||||
|
|
||||||
|
12
manual/docs/Caching - Availible options.php
Normal file
12
manual/docs/Caching - Availible options.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Doctrine_Cache offers many options for performance fine-tuning:
|
||||||
|
<ul>
|
||||||
|
<li \> savePropability <br \>
|
||||||
|
Option that defines the propability of which
|
||||||
|
a query is getting cached.
|
||||||
|
<br \><br \>
|
||||||
|
<li \> cleanPropability <br \>
|
||||||
|
Option that defines the propability the actual cleaning will occur
|
||||||
|
when calling Doctrine_Cache::clean();
|
||||||
|
<br \><br \>
|
||||||
|
<li \> statsPropability
|
||||||
|
<ul \>
|
45
manual/docs/Caching - Introduction.php
Normal file
45
manual/docs/Caching - Introduction.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php ?>
|
||||||
|
Doctrine_Cache offers an intuitive and easy-to-use query caching solution. It provides the following things:
|
||||||
|
<ul>
|
||||||
|
<li \> Multiple cache backends to choose from (including Memcached, APC and Sqlite)
|
||||||
|
<br \><br \>
|
||||||
|
|
||||||
|
<li \> Manual tuning and/or self-optimization. Doctrine_Cache knows how to optimize itself, yet it leaves user
|
||||||
|
full freedom of whether or not he/she wants to take advantage of this feature.
|
||||||
|
<br \><br \>
|
||||||
|
|
||||||
|
<li \> Advanced options for fine-tuning. Doctrine_Cache has many options for fine-tuning performance.
|
||||||
|
<br \><br \>
|
||||||
|
|
||||||
|
<li \> Cache hooks itself directly into Doctrine_Db eventlistener system allowing it to be easily added on-demand.
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<br \><br \>
|
||||||
|
Doctrine_Cache hooks into Doctrine_Db eventlistener system allowing pluggable caching.
|
||||||
|
It evaluates queries and puts SELECT statements in cache. The caching is based on propabalistics. For example
|
||||||
|
if savePropability = 0.1 there is a 10% chance that a query gets cached.
|
||||||
|
<br \><br \>
|
||||||
|
Now eventually the cache would grow very big, hence Doctrine uses propabalistic cache cleaning.
|
||||||
|
When calling Doctrine_Cache::clean() with cleanPropability = 0.25 there is a 25% chance of the clean operation being invoked.
|
||||||
|
What the cleaning does is that it first reads all the queries in the stats file and sorts them by the number of times occurred.
|
||||||
|
Then if the size is set to 100 it means the cleaning operation will leave 100 most issued queries in cache and delete all other cache entries.
|
||||||
|
<br \><br \>
|
||||||
|
|
||||||
|
|
||||||
|
<br \><br \>
|
||||||
|
Initializing a new cache instance:
|
||||||
|
<br \><br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
\$dbh = new Doctrine_Db('mysql:host=localhost;dbname=test', \$user, \$pass);
|
||||||
|
|
||||||
|
\$cache = new Doctrine_Cache('memcache');
|
||||||
|
|
||||||
|
// register it as a Doctrine_Db listener
|
||||||
|
|
||||||
|
\$dbh->addListener(\$cache);
|
||||||
|
?>");
|
||||||
|
?>
|
||||||
|
<br \><br \>
|
||||||
|
Now you know how to set up the query cache. In the next chapter you'll learn how to tweak the cache in order to get maximum performance.
|
||||||
|
<br \><br \>
|
@ -102,6 +102,7 @@ $menu = array('Getting started' =>
|
|||||||
'Introduction',
|
'Introduction',
|
||||||
'Table and class naming',
|
'Table and class naming',
|
||||||
'Field(Column) naming',
|
'Field(Column) naming',
|
||||||
|
'Column aliases',
|
||||||
'Table options',
|
'Table options',
|
||||||
'Data types and lengths',
|
'Data types and lengths',
|
||||||
'Constraints and validators',
|
'Constraints and validators',
|
||||||
@ -114,7 +115,13 @@ $menu = array('Getting started' =>
|
|||||||
'Autoincremented',
|
'Autoincremented',
|
||||||
'Natural',
|
'Natural',
|
||||||
'Composite',
|
'Composite',
|
||||||
'Sequence')
|
'Sequence'),
|
||||||
|
'Indexes' => array(
|
||||||
|
'Introduction',
|
||||||
|
'Adding indexes',
|
||||||
|
'Index options',
|
||||||
|
'Special indexes',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
'Connection management' =>
|
'Connection management' =>
|
||||||
array(
|
array(
|
||||||
@ -372,7 +379,10 @@ $menu = array('Getting started' =>
|
|||||||
|
|
||||||
array(
|
array(
|
||||||
'Introduction',
|
'Introduction',
|
||||||
'SELECT queries',
|
'SELECT queries' =>
|
||||||
|
array('DISTINCT keyword',
|
||||||
|
'Aggregate values',
|
||||||
|
),
|
||||||
'UPDATE queries',
|
'UPDATE queries',
|
||||||
'DELETE queries',
|
'DELETE queries',
|
||||||
'FROM clause',
|
'FROM clause',
|
||||||
@ -380,7 +390,6 @@ $menu = array('Getting started' =>
|
|||||||
'Conditional expressions' =>
|
'Conditional expressions' =>
|
||||||
array('Literals',
|
array('Literals',
|
||||||
'Input parameters',
|
'Input parameters',
|
||||||
|
|
||||||
'Operators and operator precedence',
|
'Operators and operator precedence',
|
||||||
'Between expressions',
|
'Between expressions',
|
||||||
'In expressions',
|
'In expressions',
|
||||||
@ -398,7 +407,10 @@ $menu = array('Getting started' =>
|
|||||||
'Collection functions'),
|
'Collection functions'),
|
||||||
|
|
||||||
'GROUP BY, HAVING clauses',
|
'GROUP BY, HAVING clauses',
|
||||||
'ORDER BY clause',
|
'ORDER BY clause'
|
||||||
|
=> array('Introduction',
|
||||||
|
'Sorting by an aggregate value',
|
||||||
|
'Using random order'),
|
||||||
'LIMIT and OFFSET clauses' =>
|
'LIMIT and OFFSET clauses' =>
|
||||||
array('Introduction',
|
array('Introduction',
|
||||||
'Driver portability',
|
'Driver portability',
|
||||||
@ -421,6 +433,16 @@ $menu = array('Getting started' =>
|
|||||||
'Isolation levels',
|
'Isolation levels',
|
||||||
'Deadlocks',
|
'Deadlocks',
|
||||||
|
|
||||||
|
),
|
||||||
|
'Caching' => array(
|
||||||
|
'Introduction',
|
||||||
|
'Availible options',
|
||||||
|
'Drivers' =>
|
||||||
|
array('Memcache',
|
||||||
|
'APC',
|
||||||
|
'Sqlite'
|
||||||
|
),
|
||||||
|
|
||||||
),
|
),
|
||||||
'Native SQL' => array(
|
'Native SQL' => array(
|
||||||
'Scalar queries',
|
'Scalar queries',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user