mirror of
https://github.com/getgrav/grav.git
synced 2026-02-20 21:48:04 +01:00
Cache tag: key is no longer required + lifetime optional
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
1. [](#improved)
|
||||
* Improved `Flex Users`: obey blueprints and allow Flex to be used in admin only
|
||||
* Improved `Flex` to support custom site template paths
|
||||
* Changed Twig `{% cache %}` tag to not need unique key, and `lifetime` is now optional
|
||||
1. [](#bugfix)
|
||||
* Fixed `Page::untranslatedLanguages()` not being symmetrical to `Page::translatedLanguages()`
|
||||
* Fixed `Flex Pages` not calling `onPageProcessed` event when cached
|
||||
|
||||
@@ -17,13 +17,13 @@ use Twig\Node\Node;
|
||||
class TwigNodeCache extends Node
|
||||
{
|
||||
/**
|
||||
* @param String $key
|
||||
* @param Int $lifetime
|
||||
* @param Node $body
|
||||
* @param integer $lineno
|
||||
* @param string $tag
|
||||
* @param string $key unique name for key
|
||||
* @param int $lifetime in seconds
|
||||
* @param Node $body
|
||||
* @param integer $lineno
|
||||
* @param string $tag
|
||||
*/
|
||||
public function __construct(String $key, int $lifetime, Node $body, $lineno, $tag = null)
|
||||
public function __construct(string $key, int $lifetime, Node $body, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('body' => $body), array( 'key' => $key, 'lifetime' => $lifetime), $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Grav\Common\Twig\TokenParser;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Twig\Node\TwigNodeCache;
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
@@ -32,7 +33,13 @@ class TwigTokenParserCache extends AbstractTokenParser
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$key = $this->parser->getVarName() . $lineno;
|
||||
$lifetime = $this->parser->getExpressionParser()->parseExpression()->getAttribute('value');
|
||||
$lifetime = Grav::instance()['cache']->getLifetime();
|
||||
|
||||
// Check for optional lifetime override
|
||||
if (!$stream->test(Token::BLOCK_END_TYPE)) {
|
||||
$lifetime_expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$lifetime = $lifetime_expr->getAttribute('value');
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideCacheEnd'), true);
|
||||
|
||||
Reference in New Issue
Block a user