@@ -232,16 +232,22 @@ async function init(prettyPrint: boolean = false) {
232232 app . runEnvironment = process . env . RunEnvironment as RunEnvironment ;
233233 app . environmentConfig =
234234 environmentConfig [ app . runEnvironment as RunEnvironment ] ;
235- app . nodeCache = new NodeCache ( { checkperiod : 30 } ) ;
235+ app . nodeCache = new NodeCache ( { checkperiod : 15 } ) ;
236236 app . dynamoClient = dynamoClient ;
237237 app . secretsManagerClient = secretsManagerClient ;
238238 app . redisClient = redisClient ;
239- app . secretConfig = secret ;
240- app . refreshSecretConfig = async ( ) => {
241- app . secretConfig = ( await getSecretValue (
242- app . secretsManagerClient ,
243- genericConfig . ConfigSecretName ,
244- ) ) as SecretConfig ;
239+ app . getCachedSecret = async ( secretName : string ) => {
240+ const cacheKey = `_SECRET:${ secretName } ` ;
241+ const cachedValue = app . nodeCache . get ( cacheKey ) ;
242+ if ( ! cachedValue ) {
243+ const realValue = ( await getSecretValue (
244+ app . secretsManagerClient ,
245+ secretName ,
246+ ) ) as SecretConfig ;
247+ app . nodeCache . set ( cacheKey , JSON . stringify ( realValue ) , 90 ) ;
248+ return realValue as SecretConfig ;
249+ }
250+ return cachedValue as SecretConfig ;
245251 } ;
246252 app . addHook ( "onRequest" , ( req , _ , done ) => {
247253 req . startTime = now ( ) ;
0 commit comments