From 04a18afe826466276636a15e902849771cb23a29 Mon Sep 17 00:00:00 2001 From: "Bean, Andrew K" Date: Wed, 10 Jan 2024 13:29:59 +0000 Subject: [PATCH] fix: cache tweaks --- src/decorators/cache-header.decorator.ts | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/decorators/cache-header.decorator.ts b/src/decorators/cache-header.decorator.ts index 0863f39..6a2698e 100644 --- a/src/decorators/cache-header.decorator.ts +++ b/src/decorators/cache-header.decorator.ts @@ -1,30 +1,33 @@ - - export function CacheHeader(durationInSeconds: number) { return function ( target: Object, key: string | symbol, - descriptor: PropertyDescriptor + descriptor: PropertyDescriptor, ) { - - let originalMethod = descriptor.value; + const originalMethod = descriptor.value; descriptor.value = async function (...args: any[]) { //console.log('Before') // Set the cache header output - let controller = this as typeof target; + const controller = this as typeof target; if (controller.hasOwnProperty('response')) { // Set the cache header output - (this as any).response.set('Surrogate-Control', 'max-age=' + durationInSeconds); - } - else { - console.warn('Controller ', target, ' does not @inject the response object. Cache header not set') + (this as any).response.set( + 'Cache-Control', + 'max-age=' + durationInSeconds, + ); + } else { + console.warn( + 'Controller ', + target, + ' does not @inject the response object. Cache header not set', + ); } // Call the original method - let result = await originalMethod.apply(this, args); + const result = await originalMethod.apply(this, args); //console.log('After') return result; - } + }; }; }