enhanced-resolve icon indicating copy to clipboard operation
enhanced-resolve copied to clipboard

Callback for whether `unsafeCache` was used to respond to a request

Open vjpr opened this issue 4 years ago • 0 comments

Would be useful to know what requests are cached by the UnsafeCachePlugin.

A cacheStatusFn or something like that would be useful. I think modifying the return value might be too intrusive.

Workaround

Use a proxy/getter on the cache object.

  const proxiedCache = new Proxy(cache, {
    get: function (target, name, receiver) {
      if (!(name in target)) {
        console.log('not cached')
        return undefined
      }
      return Reflect.get(target, name, receiver)
    },
    set: function (target, name, value, receiver) {
      if (!(name in target)) {
        console.log('caching')
      }
      return Reflect.set(target, name, value, receiver)
    },
  })

Or just implement a new UnsafeCachePlugin, but not sure how to report back...

vjpr avatar Aug 31 '21 14:08 vjpr