Skip to content

Commit

Permalink
Merge pull request #341 from micronutrientsupport/andan_bm_cache
Browse files Browse the repository at this point in the history
fix: cache tweaks
  • Loading branch information
bgsandan authored Jan 10, 2024
2 parents 2e97f9b + 04a18af commit 98ac65e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/decorators/cache-header.decorator.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};
};
}

0 comments on commit 98ac65e

Please sign in to comment.