From 97784445e604a6d57bdcd72ffb01835b464c55ca Mon Sep 17 00:00:00 2001 From: Matt Martyn Date: Fri, 25 Nov 2022 12:47:14 -0500 Subject: [PATCH] Use cache setting provided or default them if not set --- node/middlewares/cache.ts | 10 ++++++---- node/yarn.lock | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/node/middlewares/cache.ts b/node/middlewares/cache.ts index 7c7e0d9d..b19daff4 100644 --- a/node/middlewares/cache.ts +++ b/node/middlewares/cache.ts @@ -35,10 +35,12 @@ export async function cache(ctx: Context, next: () => Promise) { : THIRTY_SECONDS + from0To30() if (shouldCache) { - ctx.set( - 'cache-control', - `public, max-age=${maxAge}, stale-while-revalidate=${TEN_SECONDS_S}, stale-if-error=${TEN_MINUTES_S}` - ) + if (ctx.get('cache-control') === '') { // cache-control is not set + ctx.set( + 'cache-control', + `public, max-age=${maxAge}, stale-while-revalidate=${TEN_SECONDS_S}, stale-if-error=${TEN_MINUTES_S}` + ) + } } else { ctx.set('cache-control', 'no-store, no-cache') } diff --git a/node/yarn.lock b/node/yarn.lock index 5d894da7..74b5e8b7 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -4560,7 +4560,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -"stats-lite@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: