EXTENSIONS_CACHE_TTL: Add to allow list & decouple from other cache envs (#17464)

* EXTENSIONS_CACHE_TTL: Add to allow list & decouple from other cache envs

* Remove unnecessary import

* Broaden getCacheControlHeader function, use it for assets & extensions

* Add unit tests

* Apply suggestions from code review

Consistent lowercase "cache-control" in test description

---------

Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Pascal Jufer
2023-02-14 16:28:40 +01:00
committed by GitHub
parent 1e824f7f21
commit 45c4bc89f1
7 changed files with 256 additions and 30 deletions

View File

@@ -43,7 +43,7 @@ const checkCacheMiddleware: RequestHandler = asyncHandler(async (req, res, next)
const cacheTTL = cacheExpiryDate ? cacheExpiryDate - Date.now() : null;
res.setHeader('Cache-Control', getCacheControlHeader(req, cacheTTL));
res.setHeader('Cache-Control', getCacheControlHeader(req, cacheTTL, true, true));
res.setHeader('Vary', 'Origin, Cache-Control');
if (env.CACHE_STATUS_HEADER) res.setHeader(`${env.CACHE_STATUS_HEADER}`, 'HIT');

View File

@@ -39,7 +39,7 @@ export const respond: RequestHandler = asyncHandler(async (req, res) => {
logger.warn(err, `[cache] Couldn't set key ${key}. ${err}`);
}
res.setHeader('Cache-Control', getCacheControlHeader(req, ms(env.CACHE_TTL as string)));
res.setHeader('Cache-Control', getCacheControlHeader(req, ms(env.CACHE_TTL as string), true, true));
res.setHeader('Vary', 'Origin, Cache-Control');
} else {
// Don't cache anything by default