Skip to content

Commit

Permalink
refactor: remove redundant variable requestUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkdean committed Apr 18, 2019
1 parent a3f9d3a commit a5101cf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions dadi/lib/cache/index.js
Expand Up @@ -187,10 +187,6 @@ Cache.prototype.init = function () {
// only cache GET requests
if (req.method && req.method.toLowerCase() !== 'get') return next()

// we build the filename with a hashed hex string so we can be unique
// and avoid using file system reserved characters in the name
const requestUrl = req.url

// get the host key that matches the request's host header
const virtualHosts = config.get('virtualHosts')

Expand All @@ -199,9 +195,11 @@ Cache.prototype.init = function () {
return virtualHosts.hostnames.includes((req.headers.host || req.headers[':authority']))
}) || ''

// we build the filename with a hashed hex string so we can be unique
// and avoid using file system reserved characters in the name
const filename = crypto
.createHash('sha1')
.update(`${host}${requestUrl}`)
.update(`${host}${req.url}`)
.digest('hex')

// allow query string param to bypass cache
Expand Down Expand Up @@ -299,7 +297,7 @@ Cache.prototype.init = function () {
try {
self.cache.set(filename, Buffer.concat(data), opts).then(() => {})
} catch (e) {
console.log('Could not cache content: ' + requestUrl)
console.log('Could not cache content: ' + req.url)
}
}

Expand Down

0 comments on commit a5101cf

Please sign in to comment.