Skip to content

Commit

Permalink
Fix for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
arisk committed Sep 28, 2014
1 parent 08670ea commit 5dfb746
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions components/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5dfb746

Please sign in to comment.