I think proper Cache-Control for frontend now.

Fixed the way it handles "home" when purging frontend cache.
This commit is contained in:
Bobby Wibowo 2019-01-06 15:26:43 +07:00
parent d503d65c22
commit b431d11eba
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 12 additions and 7 deletions

View File

@ -321,11 +321,15 @@ utilsController.purgeCloudflareCache = async (names, uploads, verbose) => {
const thumbs = []
names = names.map(name => {
const url = `${domain}/${name}`
const extname = utilsController.extname(name)
if (uploads && utilsController.mayGenerateThumb(extname))
thumbs.push(`${domain}/thumbs/${name.slice(0, -extname.length)}.png`)
return url
if (uploads) {
const url = `${domain}/${name}`
const extname = utilsController.extname(name)
if (utilsController.mayGenerateThumb(extname))
thumbs.push(`${domain}/thumbs/${name.slice(0, -extname.length)}.png`)
return url
} else {
return name === 'home' ? domain : `${domain}/${name}`
}
})
try {

View File

@ -53,8 +53,9 @@ safe.use(bodyParser.json())
if (config.cacheControl) {
safe.use('/', (req, res, next) => {
// max-age: 12 hours (aimed at the HTML pages themselves)
res.set('Cache-Control', 'public, max-age=43200, must-revalidate, proxy-revalidate, stale-while-revalidate=86400, stale-if-error=86400')
// s-max-age: 30 days (only cache in proxy server)
// Obviously we have to purge proxy cache on every update
res.set('Cache-Control', 'public, s-max-age=2592000, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800')
next()
})