Asm89\Twig\CacheExtension\Node\CacheNode::compile PHP Method

compile() public method

{@inheritDoc}
public compile ( Twig_Compiler $compiler )
$compiler Twig_Compiler
    public function compile(\Twig_Compiler $compiler)
    {
        $i = self::$cacheCount++;
        if (version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) {
            $extension = 'Asm89\\Twig\\CacheExtension\\Extension';
        } else {
            $extension = 'asm89_cache';
        }
        $compiler->addDebugInfo($this)->write("\$asm89CacheStrategy" . $i . " = \$this->env->getExtension('{$extension}')->getCacheStrategy();\n")->write("\$asm89Key" . $i . " = \$asm89CacheStrategy" . $i . "->generateKey(")->subcompile($this->getNode('annotation'))->raw(", ")->subcompile($this->getNode('key_info'))->write(");\n")->write("\$asm89CacheBody" . $i . " = \$asm89CacheStrategy" . $i . "->fetchBlock(\$asm89Key" . $i . ");\n")->write("if (\$asm89CacheBody" . $i . " === false) {\n")->indent()->write("ob_start();\n")->indent()->subcompile($this->getNode('body'))->outdent()->write("\n")->write("\$asm89CacheBody" . $i . " = ob_get_clean();\n")->write("\$asm89CacheStrategy" . $i . "->saveBlock(\$asm89Key" . $i . ", \$asm89CacheBody" . $i . ");\n")->outdent()->write("}\n")->write("echo \$asm89CacheBody" . $i . ";\n");
    }