diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 80220474b..32421430a 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -67,6 +67,8 @@ abstract class BaseLoop protected $timestampable = false; protected $versionable = false; + private static $cache = array(); + /** * Create a new Loop * @@ -361,45 +363,52 @@ abstract class BaseLoop */ public function exec(&$pagination, $count = false) { - if ($this instanceof PropelSearchLoopInterface) { - $searchModelCriteria = $this->buildModelCriteria(); - if (null === $searchModelCriteria) { - $results = array(); - } else { - $results = $this->search( - $searchModelCriteria, - $pagination - ); + $hash = $this->args->getHash(); + if(false === array_key_exists($hash, self::$cache)) + { + if ($this instanceof PropelSearchLoopInterface) { + $searchModelCriteria = $this->buildModelCriteria(); + if (null === $searchModelCriteria) { + $results = array(); + } else { + $results = $this->search( + $searchModelCriteria, + $pagination + ); + } + } elseif ($this instanceof ArraySearchLoopInterface) { + $searchArray = $this->buildArray(); + if (null === $searchArray) { + $results = array(); + } else { + $results = $this->searchArray( + $searchArray, + $pagination + ); + } } - } elseif ($this instanceof ArraySearchLoopInterface) { - $searchArray = $this->buildArray(); - if (null === $searchArray) { - $results = array(); - } else { - $results = $this->searchArray( - $searchArray, - $pagination - ); + + if ($count) { + return $results ? count($results) : 0; } + + $loopResult = new LoopResult($results); + + if (true === $this->countable) { + $loopResult->setCountable(); + } + if (true === $this->timestampable) { + $loopResult->setTimestamped(); + } + if (true === $this->versionable) { + $loopResult->setVersioned(); + } + + self::$cache[$hash] = $this->parseResults($loopResult); } - if ($count) { - return $results ? count($results) : 0; - } + return self::$cache[$hash]; - $loopResult = new LoopResult($results); - - if (true === $this->countable) { - $loopResult->setCountable(); - } - if (true === $this->timestampable) { - $loopResult->setTimestamped(); - } - if (true === $this->versionable) { - $loopResult->setVersioned(); - } - - return $this->parseResults($loopResult); } protected function checkInterface() diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php index dc851098b..7f5a604c5 100644 --- a/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php +++ b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php @@ -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)); + } }