@@ -8,7 +8,8 @@ import { SecretClient, KeyVaultSecretIdentifier } from "@azure/keyvault-secrets"
88
99export class AzureKeyVaultSecretProvider {
1010 #keyVaultOptions: KeyVaultOptions | undefined ;
11- #refreshTimer: RefreshTimer | undefined ;
11+ #secretRefreshTimer: RefreshTimer | undefined ;
12+ #cacheRefreshTimer: RefreshTimer = new RefreshTimer ( 24 * 60 * 60 * 1000 ) ; // Enforce cache expiration every 24 hours
1213 #secretClients: Map < string , SecretClient > ; // map key vault hostname to corresponding secret client
1314 #cachedSecretValue: Map < string , any > = new Map < string , any > ( ) ; // map secret identifier to secret value
1415
@@ -22,7 +23,7 @@ export class AzureKeyVaultSecretProvider {
2223 }
2324 }
2425 this . #keyVaultOptions = keyVaultOptions ;
25- this . #refreshTimer = refreshTimer ;
26+ this . #secretRefreshTimer = refreshTimer ;
2627 this . #secretClients = new Map ( ) ;
2728 for ( const client of this . #keyVaultOptions?. secretClients ?? [ ] ) {
2829 const clientUrl = new URL ( client . vaultUrl ) ;
@@ -39,7 +40,7 @@ export class AzureKeyVaultSecretProvider {
3940 return this . #cachedSecretValue. get ( identifierKey ) ;
4041 }
4142
42- if ( this . #refreshTimer && ! this . #refreshTimer . canRefresh ( ) ) {
43+ if ( this . #secretRefreshTimer && ! this . #secretRefreshTimer . canRefresh ( ) ) {
4344 // If the refresh interval is not expired, return the cached value if available.
4445 if ( this . #cachedSecretValue. has ( identifierKey ) ) {
4546 return this . #cachedSecretValue. get ( identifierKey ) ;
@@ -53,6 +54,12 @@ export class AzureKeyVaultSecretProvider {
5354 }
5455
5556 clearCache ( ) : void {
57+ if ( this . #cacheRefreshTimer. canRefresh ( ) ) {
58+ // Clear the cache if the cache expiration timer has expired.
59+ this . #cachedSecretValue. clear ( ) ;
60+ this . #cacheRefreshTimer. reset ( ) ;
61+ return ;
62+ }
5663 // If the secret identifier has specified a version, it is not removed from the cache.
5764 // If the secret identifier has not specified a version, it means that the latest version should be used. Remove the cached value to force a reload.
5865 for ( const key of this . #cachedSecretValue. keys ( ) ) {
0 commit comments