@@ -129,7 +129,15 @@ export default ({config, db}) => async function (req, res, body) {
129129 if ( entityType === 'product' ) {
130130 resultProcessor . process ( _resBody . hits . hits , groupId ) . then ( async ( result ) => {
131131 _resBody . hits . hits = result
132- _cacheStorageHandler ( config , _resBody , reqHash , tagsArray )
132+ if ( config . get ( 'varnish.enabled' ) ) {
133+ // Add tags to cache, so we can display them in response headers then
134+ _cacheStorageHandler ( config , {
135+ ..._resBody ,
136+ tags : tagsArray
137+ } , reqHash , tagsArray )
138+ } else {
139+ _cacheStorageHandler ( config , _resBody , reqHash , tagsArray )
140+ }
133141 if ( _resBody . aggregations && config . entities . attribute . loadByAttributeMetadata ) {
134142 const attributeListParam = AttributeService . transformAggsToAttributeListParam ( _resBody . aggregations )
135143 // find attribute list
@@ -143,7 +151,15 @@ export default ({config, db}) => async function (req, res, body) {
143151 } else {
144152 resultProcessor . process ( _resBody . hits . hits ) . then ( ( result ) => {
145153 _resBody . hits . hits = result
146- _cacheStorageHandler ( config , _resBody , reqHash , tagsArray )
154+ if ( config . get ( 'varnish.enabled' ) ) {
155+ // Add tags to cache, so we can display them in response headers then
156+ _cacheStorageHandler ( config , {
157+ ..._resBody ,
158+ tags : tagsArray
159+ } , reqHash , tagsArray )
160+ } else {
161+ _cacheStorageHandler ( config , _resBody , reqHash , tagsArray )
162+ }
147163 res . json ( _outputFormatter ( _resBody , responseFormat ) ) ;
148164 } ) . catch ( ( err ) => {
149165 console . error ( err )
@@ -161,6 +177,11 @@ export default ({config, db}) => async function (req, res, body) {
161177 ) . then ( output => {
162178 if ( output !== null ) {
163179 res . setHeader ( 'X-VS-Cache' , 'Hit' )
180+ if ( config . get ( 'varnish.enabled' ) ) {
181+ const tagsHeader = output . tags . join ( ' ' )
182+ res . setHeader ( 'X-VS-Cache-Tags' , tagsHeader )
183+ delete output . tags
184+ }
164185 res . json ( output )
165186 console . log ( `cache hit [${ req . url } ], cached request: ${ Date . now ( ) - s } ms` )
166187 } else {
0 commit comments