Skip to content

Commit 349d678

Browse files
always clear cache
1 parent cbf3204 commit 349d678

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/keyvault/AzureKeyVaultSecretProvider.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { SecretClient, KeyVaultSecretIdentifier } from "@azure/keyvault-secrets"
99
export class AzureKeyVaultSecretProvider {
1010
#keyVaultOptions: KeyVaultOptions | undefined;
1111
#secretRefreshTimer: RefreshTimer | undefined;
12-
#cacheRefreshTimer: RefreshTimer = new RefreshTimer(24*60*60*1000); // Enforce cache expiration every 24 hours
1312
#secretClients: Map<string, SecretClient>; // map key vault hostname to corresponding secret client
1413
#cachedSecretValue: Map<string, any> = new Map<string, any>(); // map secret identifier to secret value
1514

@@ -32,8 +31,7 @@ export class AzureKeyVaultSecretProvider {
3231
}
3332

3433
async getSecretValue(secretIdentifier: KeyVaultSecretIdentifier): Promise<unknown> {
35-
// The map key is a combination of sourceId and version: "{sourceId}\n{version}".
36-
const identifierKey = `${secretIdentifier.sourceId}\n${secretIdentifier.version ?? ""}`;
34+
const identifierKey = secretIdentifier.sourceId;
3735

3836
// If the secret has a version, always use the cached value if available.
3937
if (secretIdentifier.version && this.#cachedSecretValue.has(identifierKey)) {
@@ -54,19 +52,7 @@ export class AzureKeyVaultSecretProvider {
5452
}
5553

5654
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-
}
63-
// If the secret identifier has specified a version, it is not removed from the cache.
64-
// 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.
65-
for (const key of this.#cachedSecretValue.keys()) {
66-
if (key.endsWith("\n")) {
67-
this.#cachedSecretValue.delete(key);
68-
}
69-
}
55+
this.#cachedSecretValue.clear();
7056
}
7157

7258
async #getSecretValueFromKeyVault(secretIdentifier: KeyVaultSecretIdentifier): Promise<unknown> {

0 commit comments

Comments
 (0)