/** * Last update time. * * @param string $key * @return int */ public function getTimestamp($key) { if (!$this->environment->cachable()) { //Always expired return 0; } if ($this->files->exists($key)) { return $this->files->time($key); } return 0; }
/** * {@inheritdoc} */ public function generateKey($name, $className) { $hash = hash('md5', $className . '.' . $this->environment->getID()); return $this->environment->cacheDirectory() . '/' . $hash[0] . $hash[1] . '/' . $hash . '.php'; }
/** * Modify given source. * * @param string $source Source. * @param string $namespace View namespace. * @param string $name View name (no extension included). * @return mixed */ public function modify($source, $namespace, $name) { return preg_replace_callback($this->pattern, function ($matches) { return $this->environment->getValue($matches[1]); }, $source); }
/** * {@inheritdoc} * * @return $this */ public function setEnvironment(EnvironmentInterface $environment) { $this->environment = $environment; if (!$environment->cachable()) { $this->twig->setCache(false); return $this; } $this->twig->setCache(new TwigCache($this->files, $environment)); return $this; }