key.js 430 B

1234567891011121314151617
  1. const { URL, format } = require('url')
  2. // options passed to url.format() when generating a key
  3. const formatOptions = {
  4. auth: false,
  5. fragment: false,
  6. search: true,
  7. unicode: false,
  8. }
  9. // returns a string to be used as the cache key for the Request
  10. const cacheKey = (request) => {
  11. const parsed = new URL(request.url)
  12. return `make-fetch-happen:request-cache:${format(parsed, formatOptions)}`
  13. }
  14. module.exports = cacheKey