@@ -60,7 +60,7 @@ public function nodeOpened(Latte\MacroNode $node)
6060 $ node ->empty = false ;
6161 $ node ->openingCode = Latte \PhpWriter::using ($ node )
6262 ->write (
63- '<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?> ' ,
63+ '<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) try { ?> ' ,
6464 Nette \Utils \Random::generate ()
6565 );
6666 }
@@ -73,7 +73,11 @@ public function nodeOpened(Latte\MacroNode $node)
7373 public function nodeClosed (Latte \MacroNode $ node )
7474 {
7575 $ node ->closingCode = Latte \PhpWriter::using ($ node )
76- ->write ('<?php Nette\Bridges\CacheLatte\CacheMacro::endCache($this->global->cacheStack, %node.array?); } ?> ' );
76+ ->write ('<?php
77+ Nette\Bridges\CacheLatte\CacheMacro::endCache($this->global->cacheStack, %node.array?);
78+ } catch (\Throwable $__e) {
79+ Nette\Bridges\CacheLatte\CacheMacro::rollback($this->global->cacheStack); throw $__e;
80+ } ?> ' );
7781 }
7882
7983
@@ -140,4 +144,16 @@ public static function endCache(array &$parents, array $args = null): void
140144 $ helper ->dependencies [Cache::EXPIRATION ] = $ args ['expiration ' ] ?? '+ 7 days ' ;
141145 $ helper ->end ();
142146 }
147+
148+
149+ /**
150+ * @param Nette\Caching\OutputHelper[] $parents
151+ */
152+ public static function rollback (array &$ parents ): void
153+ {
154+ $ helper = array_pop ($ parents );
155+ if ($ helper instanceof Nette \Caching \OutputHelper) {
156+ $ helper ->rollback ();
157+ }
158+ }
143159}
0 commit comments