change cache control header (stale-while-revalidate)

This commit is contained in:
spencerwooo 2022-02-12 19:37:00 +08:00
parent 8d57826e00
commit a8ea73c564
No known key found for this signature in database
GPG key ID: 24CD550268849CA0
5 changed files with 8 additions and 4 deletions

View file

@ -28,4 +28,8 @@ module.exports = {
// The directLinkRegex is used to match the direct link of the file from the response of the API. We originally use this to prevent
// unauthorised use of the proxied download feature - but that is disabled for now. So you can safely ignore this settings.
directLinkRegex: 'public[.].*[.]files[.]1drv[.]com',
// Cache-Control header, check Vercel documentation for more details.
// https://vercel.com/docs/concepts/edge-network/caching
cacheControlHeader: 'max-age=0, s-maxage=1, stale-while-revalidate=59'
}

View file

@ -133,7 +133,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Set edge function caching for faster load times, check docs:
// https://vercel.com/docs/concepts/functions/edge-caching
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
res.setHeader('Cache-Control', apiConfig.cacheControlHeader)
// Sometimes the path parameter is defaulted to '[...path]' which we need to handle
if (path === '[...path]') {

View file

@ -13,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Set edge function caching for faster load times, check docs:
// https://vercel.com/docs/concepts/functions/edge-caching
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
res.setHeader('Cache-Control', apiConfig.cacheControlHeader)
if (typeof id === 'string') {
const itemApi = `${apiConfig.driveApi}/items/${id}`

View file

@ -34,7 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Set edge function caching for faster load times, check docs:
// https://vercel.com/docs/concepts/functions/edge-caching
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
res.setHeader('Cache-Control', apiConfig.cacheControlHeader)
if (typeof searchQuery === 'string') {
// Construct Microsoft Graph Search API URL, and perform search only under the base directory

View file

@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Set edge function caching for faster load times, check docs:
// https://vercel.com/docs/concepts/functions/edge-caching
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
res.setHeader('Cache-Control', apiConfig.cacheControlHeader)
// Check whether the size is valid - must be one of 'large', 'medium', or 'small'
if (size !== 'large' && size !== 'medium' && size !== 'small') {