Class yii\authclient\CacheStateStorage

Inheritanceyii\authclient\CacheStateStorage » yii\base\Component
Implementsyii\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

Hide inherited 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

Hide inherited 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

Hide inherited properties

$cache public property

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.

public \yii\caching\Cache|array|string $cache null
$prefix public property
public $prefix 'cacheStorage'

Method Details

Hide inherited methods

get() public method

Returns the state variable value with the variable name.

public mixed get ( $key )
$key string

The variable name

return mixed

The variable value, or null if the variable does not exist.

                public function get($key)
{
    if ($this->cache !== null) {
        return $this->cache->get($this->prefix . $key);
    }
    return null;
}

            
init() public method

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);
    }
}

            
remove() public method

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;
}

            
set() public method

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);
    }
}