@@ -60,7 +60,7 @@ public function nodeOpened(Latte\MacroNode $node)
60
60
$ node ->empty = false ;
61
61
$ node ->openingCode = Latte \PhpWriter::using ($ node )
62
62
->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 { ?> ' ,
64
64
Nette \Utils \Random::generate ()
65
65
);
66
66
}
@@ -73,7 +73,11 @@ public function nodeOpened(Latte\MacroNode $node)
73
73
public function nodeClosed (Latte \MacroNode $ node )
74
74
{
75
75
$ 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
+ } ?> ' );
77
81
}
78
82
79
83
@@ -140,4 +144,16 @@ public static function endCache(array &$parents, array $args = null): void
140
144
$ helper ->dependencies [Cache::EXPIRATION ] = $ args ['expiration ' ] ?? '+ 7 days ' ;
141
145
$ helper ->end ();
142
146
}
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
+ }
143
159
}
0 commit comments