cache ParseResult for not calculating twice the same loop

This commit is contained in:
Manuel Raynaud
2014-01-24 12:09:24 +01:00
parent 3c36a3e1b2
commit 2411f5ffa3
2 changed files with 54 additions and 34 deletions

View File

@@ -67,6 +67,8 @@ abstract class BaseLoop
protected $timestampable = false;
protected $versionable = false;
private static $cache = array();
/**
* Create a new Loop
*
@@ -360,6 +362,9 @@ abstract class BaseLoop
* @return LoopResult
*/
public function exec(&$pagination, $count = false)
{
$hash = $this->args->getHash();
if(false === array_key_exists($hash, self::$cache))
{
if ($this instanceof PropelSearchLoopInterface) {
$searchModelCriteria = $this->buildModelCriteria();
@@ -399,7 +404,11 @@ abstract class BaseLoop
$loopResult->setVersioned();
}
return $this->parseResults($loopResult);
self::$cache[$hash] = $this->parseResults($loopResult);
}
return self::$cache[$hash];
}
protected function checkInterface()

View File

@@ -144,4 +144,15 @@ class ArgumentCollection implements \Iterator
{
reset($this->arguments);
}
public function getHash()
{
$arguments = $this->arguments;
if (array_key_exists('name', $arguments)) {
unset($arguments['name']);
}
return sha1(serialize($arguments));
}
}