luya\traits\CacheableTrait::getHasCache PHP Method

getHasCache() public method

Get the caching data if caching is allowed and there is any data stored for this key.
public getHasCache ( string | array $key ) : mixed | boolean
$key string | array The identifiere key, can be a string or an array which will be calculated.
return mixed | boolean Returns the data, if not found returns false.
    public function getHasCache($key)
    {
        if ($this->isCachable()) {
            $data = Yii::$app->cache->get($key);
            $enumKey = is_array($key) ? implode(",", $key) : $key;
            if ($data) {
                Yii::info("Cacheable trait key '{$enumKey}' successfully loaded from cache.", __METHOD__);
                return $data;
            }
            Yii::info("Cacheable trait key '{$enumKey}' has not been found in cache.", __METHOD__);
        }
        return false;
    }