From 15d742e938c686918b2ee716c28d5555a6f47612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Badet=20Aur=C3=A9lien?= Date: Wed, 30 Nov 2016 18:22:55 +0100 Subject: [PATCH] [BridgeAbstract] add protected property extraInfos and function getCachable() create function getCachable() modify function setDatas in call to cache->savedata --- lib/BridgeAbstract.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index c70580de..76dead53 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -11,10 +11,22 @@ abstract class BridgeAbstract implements BridgeInterface { const FORMATS = array(); // array of compatibles formats or null 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(){ + $cachable = array(); + $cachable["items"] = $this->getItems(); + $cachable["extraInfos"] = $this->getExtraInfos(); + return $cachable; + } + /** * Return items stored in the bridge * @return mixed @@ -143,7 +155,10 @@ abstract class BridgeAbstract implements BridgeInterface { if($time !== false && (time() - static::CACHE_TIMEOUT < $time) && (!defined('DEBUG') || DEBUG !== true)){ - $this->items = $this->cache->loadData(); + $cachable = array(); + $cachable = $this->cache->loadData(); + $this->items = $cachable["items"]; + $this->extraInfos = $cachable["extraInfos"]; return; } } @@ -155,7 +170,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getItems()); + $this->cache->saveData($this->getCachable()); } return; } @@ -177,7 +192,7 @@ abstract class BridgeAbstract implements BridgeInterface { $this->collectData(); if(!is_null($this->cache)){ - $this->cache->saveData($this->getItems()); + $this->cache->saveData($this->getCachable()); } } @@ -202,7 +217,7 @@ abstract class BridgeAbstract implements BridgeInterface { $extraInfos['uri']= $this->getURI(); return $extraInfos; } - + public function setCache(\CacheInterface $cache){ $this->cache = $cache; }