Nette\Caching\Cache::save PHP Method

save() public method

Dependencies are: - Cache::PRIORITY => (int) priority - Cache::EXPIRATION => (timestamp) expiration - Cache::SLIDING => (bool) use sliding expiration? - Cache::TAGS => (array) tags - Cache::FILES => (array|string) file names - Cache::ITEMS => (array|string) cache items - Cache::CONSTS => (array|string) cache items
public save ( $key, $data, array $dependencies = NULL ) : mixed
$dependencies array
return mixed value itself
    public function save($key, $data, array $dependencies = NULL)
    {
        $key = $this->generateKey($key);
        if ($data instanceof Nette\Callback || $data instanceof \Closure) {
            if ($data instanceof Nette\Callback) {
                trigger_error('Nette\\Callback is deprecated, use closure or Nette\\Utils\\Callback::toClosure().', E_USER_DEPRECATED);
            }
            $this->storage->lock($key);
            try {
                $data = call_user_func_array($data, [&$dependencies]);
            } catch (\Throwable $e) {
                $this->storage->remove($key);
                throw $e;
            } catch (\Exception $e) {
                $this->storage->remove($key);
                throw $e;
            }
        }
        if ($data === NULL) {
            $this->storage->remove($key);
        } else {
            $this->storage->write($key, $data, $this->completeDependencies($dependencies));
            return $data;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param  string $alias
  * @param  \ReflectionClass $context
  * @return string
  * @throws Exception\NamespaceNotFoundException
  */
 static function getClass($alias, \ReflectionClass $context)
 {
     if (!strlen($alias)) {
         return $alias;
     }
     if (strncmp($alias, '\\', 1) === 0) {
         return substr($alias, 1);
     }
     $file = $context->getFileName();
     if (!isset(self::$map[$file])) {
         if (self::$cache === NULL) {
             $list = Parser::parse($file);
         } else {
             $key = self::C_FILE . $file;
             $list = self::$cache->load($key);
             if ($list === NULL) {
                 $list = self::$cache->save($key, Parser::parse($file), array(NCache::FILES => array($file)));
             }
         }
         self::$map[$file] = $list;
     }
     $namespace = $context->getNamespaceName();
     if (!isset(self::$map[$file][$namespace])) {
         throw new Exception\NamespaceNotFoundException("Namespace '{$namespace}' not found in '{$file}'.");
     }
     $parts = explode('\\', $alias);
     $first = array_shift($parts);
     if (!isset(self::$map[$file][$namespace][$first])) {
         return ltrim(trim($namespace, '\\') . '\\', '\\') . $alias;
     }
     $appendix = implode('\\', $parts);
     return self::$map[$file][$namespace][$first] . (strlen($appendix) ? '\\' . $appendix : '');
 }
All Usage Examples Of Nette\Caching\Cache::save