1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/middleware/cache-control.js
2021-11-30 13:17:17 +00:00

14 lines
419 B
JavaScript

// Return a function you can pass a Response object to and it will
// set the `Cache-Control` header.
//
// For example:
//
// const cacheControlYear = getCacheControl(60 * 60 * 24 * 365)
// ...
// cacheControlYear(res)
// res.send(body)
//
export function cacheControlFactory(maxAge = 60 * 60, public_ = true) {
return (res) => res.set('cache-control', `${public_ ? 'public, ' : ''}max-age=${maxAge}`)
}