parser->getStream(); $lineno = $token->getLine(); // Parse the optional key and timeout parameters $defaults = [ 'key' => $this->parser->getVarName() . $lineno, 'lifetime' => Grav::instance()['cache']->getLifetime() ]; $key = null; $lifetime = null; while (!$stream->test(Token::BLOCK_END_TYPE)) { if ($stream->test(Token::STRING_TYPE)) { $key = $this->parser->getExpressionParser()->parseExpression(); } elseif ($stream->test(Token::NUMBER_TYPE)) { $lifetime = $this->parser->getExpressionParser()->parseExpression(); } else { throw new \Twig\Error\SyntaxError("Unexpected token type in cache tag.", $token->getLine(), $stream->getSourceContext()); } } $stream->expect(Token::BLOCK_END_TYPE); // Parse the content inside the cache block $body = $this->parser->subparse([$this, 'decideCacheEnd'], true); $stream->expect(Token::BLOCK_END_TYPE); return new TwigNodeCache($body, $key, $lifetime, $defaults, $lineno, $this->getTag()); } public function decideCacheEnd(Token $token): bool { return $token->test('endcache'); } public function getTag(): string { return 'cache'; } }