2016-02-07 04:23:23 -06:00
|
|
|
'use strict'
|
2016-02-04 14:16:27 -06:00
|
|
|
|
2016-03-16 16:29:27 -05:00
|
|
|
const cacheMiddleware = {
|
2016-02-07 04:23:23 -06:00
|
|
|
cache: cache
|
|
|
|
}
|
2016-02-04 14:16:27 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
function cache (cache) {
|
|
|
|
return function (req, res, next) {
|
|
|
|
// If we want explicitly a cache
|
|
|
|
// Or if we don't specify if we want a cache or no and we are in production
|
|
|
|
if (cache === true || (cache !== false && process.env.NODE_ENV === 'production')) {
|
|
|
|
res.setHeader('Cache-Control', 'public')
|
|
|
|
} else {
|
|
|
|
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
|
2016-02-04 14:16:27 -06:00
|
|
|
}
|
2016-02-07 04:23:23 -06:00
|
|
|
|
|
|
|
next()
|
2016-02-04 14:16:27 -06:00
|
|
|
}
|
2016-02-07 04:23:23 -06:00
|
|
|
}
|
2016-02-04 14:16:27 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
2016-02-04 14:16:27 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
module.exports = cacheMiddleware
|