yii\caching\Cache::get PHP Method

get() public method

Retrieves a value from cache with a specified key.
public get ( mixed $key ) : mixed
$key mixed a key identifying the cached value. This can be a simple string or a complex data structure consisting of factors representing the key.
return mixed the value stored in cache, false if the value is not in the cache, expired, or the dependency associated with the cached data has changed.
    public function get($key)
    {
        $key = $this->buildKey($key);
        $value = $this->getValue($key);
        if ($value === false || $this->serializer === false) {
            return $value;
        } elseif ($this->serializer === null) {
            $value = unserialize($value);
        } else {
            $value = call_user_func($this->serializer[1], $value);
        }
        if (is_array($value) && !($value[1] instanceof Dependency && $value[1]->isChanged($this))) {
            return $value[0];
        } else {
            return false;
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function load()
 {
     $contents = $this->yiiCache->get($this->key);
     if ($contents !== false) {
         $this->setFromStorage($contents);
     }
 }
All Usage Examples Of yii\caching\Cache::get