From 5dfb746cca5f5f2e5d0a3225885c5706bf7a92b2 Mon Sep 17 00:00:00 2001 From: Aris Karageorgos Date: Mon, 29 Sep 2014 01:08:13 +0700 Subject: [PATCH] Fix for #1 --- components/Settings.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/components/Settings.php b/components/Settings.php index d45cecd..02d2028 100755 --- a/components/Settings.php +++ b/components/Settings.php @@ -39,18 +39,21 @@ class Settings extends Component public $cache = 'cache'; /** - * To be used by the cache component. + * @var Cache|string the front cache object or the application component ID of the front cache object. + * Front cache will be cleared through this cache object, if it is available. * - * @var string cache key + * After the Settings object is created, if you want to change this property, + * you should only assign it with a cache object. + * Set this property to null if you do not want to clear the front cache. */ - public $cacheKey = 'pheme/settings'; + public $frontCache; /** - * Allow the component to clear the front application cache if available. + * To be used by the cache component. * - * @var string cache key prefix + * @var string cache key */ - public $frontKeyPrefix; + public $cacheKey = 'pheme/settings'; /** * Holds a cached copy of the data for the current request @@ -73,6 +76,9 @@ public function init() if (is_string($this->cache)) { $this->cache = Yii::$app->get($this->cache, false); } + if (is_string($this->frontCache)) { + $this->frontCache = Yii::$app->get($this->frontCache, false); + } } /** @@ -198,13 +204,10 @@ public function deactivate($key, $section = null) public function clearCache() { $this->_data = null; + if ($this->frontCache instanceof Cache) { + $this->frontCache->delete($this->cacheKey); + } if ($this->cache instanceof Cache) { - if (!is_null($this->frontKeyPrefix)) { - $backendKeyPrefix = $this->cache->keyPrefix; - $this->cache->keyPrefix = $this->frontKeyPrefix; - $this->cache->delete($this->cacheKey); - $this->cache->keyPrefix = $backendKeyPrefix; - } return $this->cache->delete($this->cacheKey); } return true;