Skip to content

Commit

Permalink
chore: update cache headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Aug 22, 2021
1 parent 1c8a667 commit dc0a6f4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ const render = ({ body, response, flags }) => {
}
}

const cache = headers['x-cache-status']
const expiredAt =
cache === 'HIT' ? `(${headers['x-cache-expired-at']} left)` : ''

const cacheStatus = headers['cf-cache-status'] || headers['x-cache-status']
const timestamp = Number(headers['x-timestamp'])
const ttl = Number(headers['x-cache-ttl'])
const expires = timestamp + ttl - Date.now()
const expiration = prettyMs(expires)
const expiredAt = cacheStatus === 'HIT' ? `(${expiration})` : ''
const fetchMode = headers['x-fetch-mode']
const fetchTime = fetchMode && `(${headers['x-fetch-time']})`
const size = Number(headers['content-length'] || Buffer.byteLength(body))
Expand All @@ -146,12 +148,12 @@ const render = ({ body, response, flags }) => {
)
console.log()

if (cache) {
if (cacheStatus) {
console.log(
'',
print.keyValue(
chalk.green('cache'),
`${cache || '-'} ${chalk.gray(expiredAt)}`
`${cacheStatus || '-'} ${chalk.gray(expiredAt)}`
)
)
}
Expand All @@ -166,8 +168,8 @@ const render = ({ body, response, flags }) => {
)
}

console.log(cache ? ' ' : '', print.keyValue(chalk.green('uri'), uri))
console.log(cache ? ' ' : ' ', print.keyValue(chalk.green('id'), id))
console.log(cacheStatus ? ' ' : '', print.keyValue(chalk.green('uri'), uri))
console.log(cacheStatus ? ' ' : ' ', print.keyValue(chalk.green('id'), id))

if (flags.copy) {
let copiedValue
Expand Down

0 comments on commit dc0a6f4

Please sign in to comment.