import env from '../env' ; import { Request } from 'express' ; param req param ttl export function getCacheControlHeader ( req , ttl ) { if ( ttl === null ) return 'no-cache' ; if ( env . CACHE_AUTO_PURGE === true ) return 'no-cache' ; const noCacheRequested = req . headers [ 'cache-control' ] ?. includes ( 'no-store' ) || req . headers [ 'Cache-Control' ] ?. includes ( 'no-store' ) ; if ( noCacheRequested ) return 'no-store' ; const ttlSeconds = Math . round ( ttl / 1000 ) ; const access = ! ! req . accountability ?. role === false ? 'public' : 'private' ; let headerValue = `${ access }, max-age=${ ttlSeconds }` ; if ( env . CACHE_CONTROL_S_MAXAGE !== false ) { if ( env . CACHE_CONTROL_S_MAXAGE === true ) { headerValue += `, s-maxage=${ ttlSeconds }` ; } else { headerValue += `, s-maxage=${ env . CACHE_CONTROL_S_MAXAGE }` ; } } return headerValue ; }