@@ -187,6 +187,10 @@ async function fastifyView (fastify, opts) {
187
187
return result
188
188
}
189
189
190
+ function getCacheKey ( key ) {
191
+ return [ propertyName , key ] . join ( '|' )
192
+ }
193
+
190
194
function getDefaultExtension ( type ) {
191
195
const mappedExtensions = {
192
196
handlebars : 'hbs' ,
@@ -223,7 +227,7 @@ async function fastifyView (fastify, opts) {
223
227
if ( type === 'handlebars' ) {
224
228
data = engine . compile ( data , globalOptions . compileOptions )
225
229
}
226
- fastify [ viewCache ] . set ( file , data )
230
+ fastify [ viewCache ] . set ( getCacheKey ( file ) , data )
227
231
return data
228
232
}
229
233
@@ -238,7 +242,7 @@ async function fastifyView (fastify, opts) {
238
242
isRaw = true
239
243
file = file . raw
240
244
}
241
- const data = fastify [ viewCache ] . get ( file )
245
+ const data = fastify [ viewCache ] . get ( getCacheKey ( file ) )
242
246
if ( data && prod ) {
243
247
return data
244
248
}
@@ -270,7 +274,7 @@ async function fastifyView (fastify, opts) {
270
274
}
271
275
272
276
function getPartialsCacheKey ( page , partials , requestedPath ) {
273
- let cacheKey = page
277
+ let cacheKey = getCacheKey ( page )
274
278
275
279
for ( const key of Object . keys ( partials ) ) {
276
280
cacheKey += `|${ key } :${ partials [ key ] } `
@@ -295,7 +299,7 @@ async function fastifyView (fastify, opts) {
295
299
296
300
const compiledPage = engine . compile ( html , localOptions )
297
301
298
- fastify [ viewCache ] . set ( page , compiledPage )
302
+ fastify [ viewCache ] . set ( getCacheKey ( page ) , compiledPage )
299
303
return compiledPage
300
304
}
301
305
@@ -345,7 +349,7 @@ async function fastifyView (fastify, opts) {
345
349
// append view extension
346
350
page = getPage ( page , type )
347
351
}
348
- const toHtml = fastify [ viewCache ] . get ( page )
352
+ const toHtml = fastify [ viewCache ] . get ( getCacheKey ( page ) )
349
353
350
354
if ( toHtml && prod ) {
351
355
return toHtml ( data )
@@ -376,7 +380,7 @@ async function fastifyView (fastify, opts) {
376
380
// append view extension
377
381
page = getPage ( page , type )
378
382
}
379
- const toHtml = fastify [ viewCache ] . get ( page )
383
+ const toHtml = fastify [ viewCache ] . get ( getCacheKey ( page ) )
380
384
381
385
if ( toHtml && prod ) {
382
386
return toHtml ( data )
@@ -630,7 +634,7 @@ async function fastifyView (fastify, opts) {
630
634
}
631
635
632
636
function hasAccessToLayoutFile ( fileName , ext ) {
633
- const layoutKey = `layout-${ fileName } -${ ext } `
637
+ const layoutKey = getCacheKey ( `layout-${ fileName } -${ ext } ` )
634
638
let result = fastify [ viewCache ] . get ( layoutKey )
635
639
636
640
if ( typeof result === 'boolean' ) {
0 commit comments