From 670d8f18cb32eef1190caed2afce05ef8b9ad87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Badet=20Aur=C3=A9lien?= Date: Tue, 3 Jan 2017 11:28:47 +0100 Subject: [PATCH] [BridgeAbstract] Enable caching of extraInfos - Issue #431 (#434) Enable caching of extraInfos. --- lib/BridgeAbstract.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 0be9423..6d35ba4 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -10,10 +10,19 @@ abstract class BridgeAbstract implements BridgeInterface { const PARAMETERS = array(); protected $cache; + protected $extraInfos; protected $items = array(); protected $inputs = array(); protected $queriedContext = ''; + /** + * Return cachable datas (extrainfos and items) stored in the bridge + * @return mixed + */ + public function getCachable(){ + return array("items" => $this->getItems(), "extraInfos" => $this->getExtraInfos()); + } + /** * Return items stored in the bridge * @return mixed @@ -142,8 +151,12 @@ abstract class BridgeAbstract implements BridgeInterface { if($time !== false && (time() - static::CACHE_TIMEOUT < $time) && (!defined('DEBUG') || DEBUG !== true)){ - $this->items = $this->cache->loadData(); - return; + $cached = $this->cache->loadData(); + if(isset($cached['items']) && isset($cached['extraInfos'])){ + $this->items = $cached['items']; + $this->extraInfos = $cached['extraInfos']; + return; + } } } @@ -154,7 +167,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getItems()); + $this->cache->saveData($this->getCachable()); } return; } @@ -176,7 +189,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getItems()); + $this->cache->saveData($this->getCachable()); } } @@ -196,10 +209,7 @@ abstract class BridgeAbstract implements BridgeInterface { } public function getExtraInfos(){ - $extraInfos = array(); - $extraInfos['name'] = $this->getName(); - $extraInfos['uri'] = $this->getURI(); - return $extraInfos; + return array("name" => $this->getName(), "uri" => $this->getURI()); } public function setCache(\CacheInterface $cache){