StackFormation\Helper\Cache::get PHP Метод

get() публичный Метод

Get (and generate)
public get ( $key, callable $callback = null, boolean $fresh = false ) : mixed
$key
$callback callable
$fresh boolean
Результат mixed
    public function get($key, callable $callback = null, $fresh = false)
    {
        if ($fresh || !$this->has($key)) {
            if (!is_null($callback)) {
                $this->set($key, $callback());
            } else {
                throw new \Exception(sprintf("Cache key '%s' not found.", $key));
            }
        }
        /* else {
               echo "HIT!";
           } */
        return $this->cache[$key];
    }

Usage Example

Пример #1
0
 public function getTemplate()
 {
     return $this->cache->get(__METHOD__, function () {
         $res = $this->cfnClient->getTemplate(['StackName' => $this->getName()]);
         return $res->get('TemplateBody');
     });
 }