@@ -39,13 +39,13 @@ function etagHandleRequest (req, res, next) {
3939 } )
4040}
4141
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 ( )
4545 this . cache . set (
4646 { id : etag , segment : this . cacheSegment } ,
4747 true ,
48- fastifyReply . _etagLife ,
48+ res . _etagLife ,
4949 next
5050 )
5151}
@@ -67,8 +67,8 @@ function fastifyCachingPlugin (instance, options, next) {
6767 value = `${ _options . privacy } , max-age=${ _options . expiresIn } `
6868 }
6969
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 )
7272 next ( )
7373 } )
7474 }
@@ -81,6 +81,7 @@ function fastifyCachingPlugin (instance, options, next) {
8181 instance . addHook ( 'onRequest' , etagHandleRequest )
8282 instance . addHook ( 'onSend' , etagOnSend )
8383
84+ instance [ Symbol . for ( 'fastify-caching.registered' ) ] = true
8485 next ( )
8586}
8687
0 commit comments