Commit b3ad23bb authored by zYne's avatar zYne

cache implementation continues

parent 20e23d99
...@@ -216,15 +216,11 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite ...@@ -216,15 +216,11 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$rand = (mt_rand() / mt_getrandmax()); $rand = (mt_rand() / mt_getrandmax());
if ($rand <= $this->_options['cleanPropability']) { if ($rand <= $this->_options['cleanPropability']) {
$content = file_get_contents($this->_statsFile); $queries = $this->readStats();
$queries = explode("\n", $content);
$stats = array(); $stats = array();
foreach ($queries as $query) { foreach ($queries as $query) {
if (is_array($query)) {
$query = $query[0];
}
if (isset($stats[$query])) { if (isset($stats[$query])) {
$stats[$query]++; $stats[$query]++;
} else { } else {
...@@ -238,17 +234,29 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite ...@@ -238,17 +234,29 @@ 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);
if (is_array($query)) { $hash = md5($query);
$hash = md5(serialize($query));
} else {
$hash = md5($query);
}
$this->_driver->delete($hash); $this->_driver->delete($hash);
} }
} }
} }
/**
* readStats
*
* @return array
*/
public function readStats()
{
if ($this->_options['statsFile'] !== false) {
$content = file_get_contents($this->_options['statsFile']);
$e = explode("\n", $content);
return array_map('unserialize', $e);
}
return array();
}
/** /**
* appendStats * appendStats
* *
...@@ -266,7 +274,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite ...@@ -266,7 +274,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$rand = (mt_rand() / mt_getrandmax()); $rand = (mt_rand() / mt_getrandmax());
if ($rand <= $this->_options['addStatsPropability']) { if ($rand <= $this->_options['addStatsPropability']) {
file_put_contents($this->_options['statsFile'], implode("\n", $this->_queries)); file_put_contents($this->_options['statsFile'], implode("\n", array_map('serialize', $this->_queries)));
} }
} }
} }
...@@ -289,7 +297,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite ...@@ -289,7 +297,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this->add($query, $event->getInvoker()->getName()); $this->add($query, $event->getInvoker()->getName());
$data = $this->_driver->fetch(md5($query)); $data = $this->_driver->fetch(md5(serialize($query)));
$this->success = ($data) ? true : false; $this->success = ($data) ? true : false;
...@@ -303,7 +311,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite ...@@ -303,7 +311,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this->success = true; $this->success = true;
$this->_driver->save(md5($query), $data); $this->_driver->save(md5(serialize($query)), $data);
} }
} }
$this->_data = $data; $this->_data = $data;
......
...@@ -36,7 +36,7 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun ...@@ -36,7 +36,7 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun
* @var array $definition * @var array $definition
*/ */
protected $_definition = array( protected $_definition = array(
'type', 'type' => null,
'length' => 0, 'length' => 0,
); );
/** /**
...@@ -46,6 +46,22 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun ...@@ -46,6 +46,22 @@ class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Coun
{ {
$this->_definition = $definition; $this->_definition = $definition;
} }
/**
* @return array
*/
public function getDefinition()
{
return $this->_definition;
}
/**
* contains
*
* @return boolean
*/
public function contains($name)
{
return isset($this->_definition[$name]);
}
/** /**
* get * get
* *
......
...@@ -50,6 +50,10 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface ...@@ -50,6 +50,10 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
{ {
return $this->adapter; return $this->adapter;
} }
public function getStatement()
{
return $this->stmt;
}
public function getQuery() public function getQuery()
{ {
return $this->stmt->queryString; return $this->stmt->queryString;
......
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