Nette\Caching\Cache::load PHP Method

load() public method

Reads the specified item from the cache or generate it.
public load ( $key, $fallback = NULL ) : mixed | null
return mixed | null
    public function load($key, $fallback = NULL)
    {
        $data = $this->storage->read($this->generateKey($key));
        if ($data === NULL && $fallback) {
            return $this->save($key, function (&$dependencies) use($fallback) {
                return call_user_func_array($fallback, [&$dependencies]);
            });
        }
        return $data;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param string $name
  * @return string
  */
 public function link($name)
 {
     $path = $this->cache->load([$name, $this->debugMode]);
     $files = $this->files[$name];
     $files = is_string($files) ? [$files] : $files;
     if ($path === NULL) {
         $unpackedFiles = $this->unpack($name, $files);
         $time = $this->getModifyTime($unpackedFiles);
         $path = $this->genDir . '/' . $this->getOutputFilename($name, $unpackedFiles, $time, $this->debugMode);
         $this->cache->save([$name, $this->debugMode], $path);
     }
     $genFile = "{$this->wwwDir}/{$path}";
     if (!file_exists($genFile) || $this->debugMode && filemtime($genFile) < (isset($time) ? $time : ($time = $this->getModifyTime($this->unpack($name, $files))))) {
         $start = microtime(TRUE);
         $parsedFiles = $this->compile($this->unpack($name, $files), $genFile);
         if ($this->debugMode) {
             $this->statistics[$name]['time'] = microtime(TRUE) - $start;
             $this->statistics[$name]['parsedFiles'] = $parsedFiles;
         }
     }
     if ($this->debugMode) {
         $unpackedFiles = $this->unpack($name, $files);
         $this->statistics[$name]['size'] = filesize($genFile);
         $this->statistics[$name]['file'] = count($unpackedFiles) > 1 ? $unpackedFiles : reset($unpackedFiles);
         $this->statistics[$name]['date'] = isset($time) ? $time : ($time = $this->getModifyTime($unpackedFiles));
         $this->statistics[$name]['path'] = $path;
     }
     return $path;
 }
All Usage Examples Of Nette\Caching\Cache::load