Commit 35a760aa authored by zYne's avatar zYne

--no commit message

--no commit message
parent 42827580
......@@ -38,8 +38,8 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
protected $_options = array('size' => 1000,
'lifeTime' => 3600,
'statsPropability' => 0.75,
'savePropability' => 0.80,
'cleanPropability' => 0.98,
'savePropability' => 0.10,
'cleanPropability' => 0.01,
'statsFile' => '../data/stats.cache',
);
/**
......@@ -270,6 +270,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
{
$query = $event->getQuery();
$data = false;
// only process SELECT statements
if (substr(trim(strtoupper($query)), 0, 6) == 'SELECT') {
......@@ -279,12 +280,22 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this->success = ($data) ? true : false;
$this->_data = $data;
if ( ! $data) {
$rand = (rand(1, 10000) / (10000 * 100));
return true;
}
if ($rand < $this->_options['savePropability']) {
$stmt = $event->getInvoker()->query($query);
return false;
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
$this->success = true;
$this->_driver->save(md5($query), $data);
}
}
$this->_data = $data;
}
return (bool) $data;
}
/**
* onPreFetch
......@@ -326,6 +337,8 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
{
$query = $event->getQuery();
$data = false;
// only process SELECT statements
if (substr(trim(strtoupper($query)), 0, 6) == 'SELECT') {
......@@ -335,28 +348,31 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this->success = ($data) ? true : false;
$this->_data = $data;
if ( ! $data) {
$rand = (rand(1, 10000) / (10000 * 100));
return true;
if ($rand < $this->_options['savePropability']) {
$stmt = $event->getInvoker()->execute($event->getParams());
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
$this->success = true;
$this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
}
}
return false;
$this->_data = $data;
}
return (bool) $data;
}
/**
* onExecute
* listens the onExecute event of Doctrine_Db_Statement
*
* adds the issued query to internal query stack
* and checks if cached element exists
*
* @return boolean
*/
/**
* destructor
* processStats
*
* @return void
*/
public function process()
public function processStats()
{
$rand = (rand(1, 10000) / (10000 * 100));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment