Skip to content

Commit

Permalink
Update CacheBehavior.php
Browse files Browse the repository at this point in the history
  • Loading branch information
cornernote committed Feb 27, 2018
1 parent 5c3398c commit fd1a3cc
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/CacheBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,6 @@ public function clearCache($resetCleared = true)
$this->clearCacheKeyPrefix();
}

/**
* Clear the cache prefix.
*
* @param null|string $cacheKeyPrefix
*/
protected function clearCacheKeyPrefix()
{
Yii::$app->{$this->cache}->delete($this->cacheKeyPrefixName);
if ($this->backupCache) {
Yii::$app->{$this->backupCache}->delete($this->cacheKeyPrefixName);
}
}

/**
* Get the cache prefix.
*
Expand All @@ -189,6 +176,37 @@ public function getCacheKeyPrefix()
return $cacheKeyPrefix;
}

/**
* Set the cache prefix.
*
* @param null|string $cacheKeyPrefix
*/
public function setCacheKeyPrefix($cacheKeyPrefix = null)
{
$cacheKeyPrefixName = $this->getCacheKeyPrefixName();
if (!$cacheKeyPrefix) {
$cacheKeyPrefix = uniqid();
}
Yii::$app->{$this->cache}->set($cacheKeyPrefixName, $cacheKeyPrefix);
if ($this->backupCache) {
Yii::$app->{$this->backupCache}->set($cacheKeyPrefixName, $cacheKeyPrefix);
}
}


/**
* Clear the cache prefix.
*
* @param null|string $cacheKeyPrefix
*/
protected function clearCacheKeyPrefix()
{
Yii::$app->{$this->cache}->delete($this->cacheKeyPrefixName);
if ($this->backupCache) {
Yii::$app->{$this->backupCache}->delete($this->cacheKeyPrefixName);
}
}

/**
* Get the cache prefix name.
*
Expand Down

0 comments on commit fd1a3cc

Please sign in to comment.