-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from micronutrientsupport/andan_bm_cache
fix: cache tweaks
- Loading branch information
Showing
1 changed file
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
}; | ||
} |