@@ -26,7 +26,7 @@ function etag (value, lifetime) {
2626 return this
2727}
2828
29- function etagHandleRequest ( req , res , next ) {
29+ function cachingLoadByEtag ( req , res , next ) {
3030 if ( ! req . headers [ 'if-none-match' ] ) return next ( )
3131 const etag = req . headers [ 'if-none-match' ]
3232 this . cache . get ( { id : etag , segment : this . cacheSegment } , ( err , cached ) => {
@@ -38,7 +38,7 @@ function etagHandleRequest (req, res, next) {
3838 } )
3939}
4040
41- function etagOnSend ( req , res , payload , next ) {
41+ function cachingStoreByEtag ( req , res , payload , next ) {
4242 const etag = res . getHeader ( 'etag' )
4343 if ( ! etag || ! res . _etagLife ) return next ( )
4444 this . cache . set (
@@ -70,7 +70,7 @@ function fastifyCaching (instance, options, next) {
7070 value += `, s-maxage=${ _options . serverExpiresIn } `
7171 }
7272
73- instance . addHook ( 'onRequest' , ( req , res , next ) => {
73+ instance . addHook ( 'onRequest' , function cachingSetCacheControlHeader ( req , res , next ) {
7474 if ( ! res . hasHeader ( 'Cache-control' ) ) {
7575 res . header ( 'Cache-control' , value )
7676 }
@@ -83,8 +83,8 @@ function fastifyCaching (instance, options, next) {
8383 instance . decorate ( 'etagMaxLife' , _options . etagMaxLife )
8484 instance . decorateReply ( 'etag' , etag )
8585 instance . decorateReply ( 'expires' , cachingExpires )
86- instance . addHook ( 'onRequest' , etagHandleRequest )
87- instance . addHook ( 'onSend' , etagOnSend )
86+ instance . addHook ( 'onRequest' , cachingLoadByEtag )
87+ instance . addHook ( 'onSend' , cachingStoreByEtag )
8888
8989 instance [ Symbol . for ( 'fastify-caching.registered' ) ] = true
9090 next ( )
0 commit comments