File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,8 @@ public function __construct(array $props = [], bool $setInstance = true)
102102 $ this ->core = new Core ($ this );
103103 $ this ->events = new Events ($ this );
104104
105- // start with a fresh version cache
105+ // start with a fresh snippet and version cache
106+ Snippet::resetCache ();
106107 VersionCache::reset ();
107108
108109 // register all roots to be able to load stuff afterwards
Original file line number Diff line number Diff line change 2323 */
2424class Snippet extends Tpl
2525{
26+ /**
27+ * Cache for the snippet files
28+ */
29+ public static array $ cache = [];
30+
2631 /**
2732 * Cache for the currently active
2833 * snippet. This is used to start
@@ -182,18 +187,25 @@ public static function file(string|array $name): string|null
182187
183188 foreach ($ names as $ name ) {
184189 $ name = (string )$ name ;
190+
191+ // retrieve the file from the cache if it exists
192+ if (isset (static ::$ cache [$ name ]) === true ) {
193+ return static ::$ cache [$ name ];
194+ }
195+
185196 $ file = $ root . '/ ' . $ name . '.php ' ;
186197
187198 if (F::exists ($ file , $ root ) === false ) {
188199 $ file = $ kirby ->extensions ('snippets ' )[$ name ] ?? null ;
189200 }
190201
191202 if ($ file ) {
192- break ;
203+ // cache the file for future use
204+ return static ::$ cache [$ name ] = $ file ;
193205 }
194206 }
195207
196- return $ file ;
208+ return null ;
197209 }
198210
199211 /**
@@ -249,6 +261,11 @@ public function render(array $data = [], array $slots = []): string
249261 );
250262 }
251263
264+ public static function resetCache (): void
265+ {
266+ static ::$ cache = [];
267+ }
268+
252269 /**
253270 * Returns the root directory for all
254271 * snippet templates
You can’t perform that action at this time.
0 commit comments