nuxt-multi-cache icon indicating copy to clipboard operation
nuxt-multi-cache copied to clipboard

How to add a cache hit marker? For example, add a response header X-cache-status: HIT.

Open yisibell opened this issue 5 months ago • 2 comments

How to add a cache hit marker? For example, add a response header X-cache-status: HIT.

yisibell avatar Jul 22 '25 09:07 yisibell

Currently that's not directly possible to do yourself, but this could easily be added as a feature to the module when returning a route from cache. Would probably also make sense to add additional headers for debugging purposes, such as time cached and expiration.

dulnan avatar Jul 22 '25 10:07 dulnan

Currently that's not directly possible to do yourself, but this could easily be added as a feature to the module when returning a route from cache. Would probably also make sense to add additional headers for debugging purposes, such as time cached and expiration.

import { defineMultiCacheOptions } from 'nuxt-multi-cache/server-options'

export default defineMultiCacheOptions(() => {
  return {
    route: {
      alterCachedHeaders(headers) {

        // Add a response header mark
        headers['X-cache-status'] = 'HIT'

        return headers
      },
    },
  }
})

For cases that have been cached, this is ok.

yisibell avatar Jul 22 '25 10:07 yisibell