Class yii\authclient\CacheStateStorage
Inheritance | yii\authclient\CacheStateStorage » yii\base\Component |
---|---|
Implements | yii\authclient\StateStorageInterface |
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/src/CacheStateStorage.php |
CacheStateStorage provides Auth client state storage based in cache component.
See also yii\authclient\StateStorageInterface.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$cache | \yii\caching\Cache|array|string | Cache object or the application component ID of the cache object to be used. | yii\authclient\CacheStateStorage |
$prefix | yii\authclient\CacheStateStorage |
Public Methods
Method | Description | Defined By |
---|---|---|
get() | Returns the state variable value with the variable name. | yii\authclient\CacheStateStorage |
init() | yii\authclient\CacheStateStorage | |
remove() | Removes a state variable. | yii\authclient\CacheStateStorage |
set() | Adds a state variable. | yii\authclient\CacheStateStorage |
Property Details
Cache object or the application component ID of the cache object to be used.
After the CacheStateStorage object is created, if you want to change this property, you should only assign it with a cache object.
If not set - application 'cache' component will be used, but only, if it is available (e.g. in web application), otherwise - no cache will be used and no data saving will be performed.
Method Details
Returns the state variable value with the variable name.
public mixed get ( $key ) | ||
$key | string |
The variable name |
return | mixed |
The variable value, or |
---|
public function get($key)
{
if ($this->cache !== null) {
return $this->cache->get($this->prefix . $key);
}
return null;
}
public void init ( ) |
public function init()
{
parent::init();
if ($this->cache === null) {
if (Yii::$app->has('cache')) {
$this->cache = Yii::$app->get('cache');
}
} else {
$this->cache = Instance::ensure($this->cache, Cache::class);
}
}
Removes a state variable.
public boolean remove ( $key ) | ||
$key | string |
The name of the variable to be removed |
return | boolean |
Success. |
---|
public function remove($key)
{
if ($this->cache !== null) {
return $this->cache->delete($this->prefix . $key);
}
return true;
}
Adds a state variable.
If the specified name already exists, the old value will be overwritten.
public void set ( $key, $value ) | ||
$key | string |
Variable name |
$value | mixed |
Variable value |
public function set($key, $value)
{
if ($this->cache !== null) {
$this->cache->set($this->prefix . $key, $value);
}
}