[BridgeAbstract] Enable caching of extraInfos - Issue #431 (#434)

Enable caching of extraInfos.
This commit is contained in:
Badet Aurélien 2017-01-03 11:28:47 +01:00 committed by Teromene
parent a4f4447c5e
commit 670d8f18cb

View file

@ -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){