Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback for whether unsafeCache was used to respond to a request #300

Open
vjpr opened this issue Aug 31, 2021 · 0 comments
Open

Callback for whether unsafeCache was used to respond to a request #300

vjpr opened this issue Aug 31, 2021 · 0 comments

Comments

@vjpr
Copy link

vjpr commented Aug 31, 2021

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 vjpr changed the title Callback for whether unsafe cache was used for a request Callback for whether unsafeCache was used to respond to a request Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant