Files
shields/services/debug/debug.service.js
Paul Melnikow 46b98c40be Remove the in-memory cache (#6037)
Shields has long had an in-memory cache with some complex logic for determining when the cached values are used and when they are flushed. At the time this was implemented, squeezing cache performance was helpful since there was no downstream cache. For years now we've used Cloudflare as a CDN, so trying to cache onboard is less useful than before. Furthermore, since the cache is very small and only used in fairly restrictive ways, it probably has very little impact on performance.
2021-01-11 15:53:36 -05:00

45 lines
1.0 KiB
JavaScript

'use strict'
const { BaseService } = require('..')
const serverStartTime = new Date(new Date().toGMTString())
let bitFlip = false
module.exports = class Debug extends BaseService {
static category = 'debug'
static route = { base: 'debug', pattern: ':variant(time|starttime|flip)' }
static defaultBadgeData = { label: 'debug', color: 'blue' }
async handle({ variant }) {
switch (variant) {
case 'time':
return {
label: 'time',
message: new Date().toUTCString(),
}
case 'starttime':
return {
label: 'start time',
message: new Date(serverStartTime).toUTCString(),
}
// For production cache debugging.
case 'flip':
bitFlip = !bitFlip
if (bitFlip) {
return {
label: 'flip',
message: 'on',
color: 'brightgreen',
}
} else {
return {
label: 'flip',
message: 'off',
color: 'red',
}
}
}
}
}