mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
@@ -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');
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user