@@ -39,13 +39,13 @@ function etagHandleRequest (req, res, next) {
39
39
} )
40
40
}
41
41
42
- function etagOnSend ( fastifyRequest , fastifyReply , payload , next ) {
43
- const etag = fastifyReply . getHeader ( 'etag' )
44
- if ( ! etag || ! fastifyReply . _etagLife ) return next ( )
42
+ function etagOnSend ( req , res , payload , next ) {
43
+ const etag = res . getHeader ( 'etag' )
44
+ if ( ! etag || ! res . _etagLife ) return next ( )
45
45
this . cache . set (
46
46
{ id : etag , segment : this . cacheSegment } ,
47
47
true ,
48
- fastifyReply . _etagLife ,
48
+ res . _etagLife ,
49
49
next
50
50
)
51
51
}
@@ -67,8 +67,8 @@ function fastifyCachingPlugin (instance, options, next) {
67
67
value = `${ _options . privacy } , max-age=${ _options . expiresIn } `
68
68
}
69
69
70
- instance . addHook ( 'preHandler ' , ( fastifyReq , fastifyReply , next ) => {
71
- fastifyReply . header ( 'Cache-control' , value )
70
+ instance . addHook ( 'onRequest ' , ( req , res , next ) => {
71
+ res . header ( 'Cache-control' , value )
72
72
next ( )
73
73
} )
74
74
}
@@ -81,6 +81,7 @@ function fastifyCachingPlugin (instance, options, next) {
81
81
instance . addHook ( 'onRequest' , etagHandleRequest )
82
82
instance . addHook ( 'onSend' , etagOnSend )
83
83
84
+ instance [ Symbol . for ( 'fastify-caching.registered' ) ] = true
84
85
next ( )
85
86
}
86
87
0 commit comments