My Azure Keys Vaults Secrets contains my connection string. My app only connects to my Azure Vault during the app Startup.cs and then saves the connection string in a static class for use elsewhere.
I noticed a few days ago that Key Vaults Metrics was showing 2.45k hits during a 6 minute interval.
Here is the Starup.cs code:
public class Startup
{
var SecretUri = config["SecretUri"];
var TenantId = config["TenantId"];
var ClientSecret = config["ClientSecret"];
var ClientId = config["ClientId"];
var secretclient = new SecretClient(new Uri(SecretUri), new ClientSecretCredential(TenantId, ClientId, ClientSecret));
KeyVaultSecret keyv = secretclient.GetSecret("{myconnection_secretname}");
SecretServices.ConnectionString = keyv.Value;
}
From this point I use the SecretServices.ConnectionString anywhere else in the app where I need the connection string.
My question is there any way my app can hit the vault 2000 times in a few minutes or is something else happening?
Here is the graph from Azure Vaults Metrics Total API Hits:

This graph shows the sudden jump in the number of hits to the API Service.
Thanks @ Tore Nestenius for the comment.
If the
Key Vault Metricsshow 2.45k hits, you may want to investigate other areas of your system to see if other components are accessing the Key Vault. For example, it's possible that somebackground jobsorscheduled tasksare hitting theKey Vaultrepeatedly.You might also want to consider reducing the frequency with which your app accesses the Key Vault by caching the connection string in memory after retrieving it on startup. That way, your app would only need to retrieve the connection string from the Key Vault once, which would reduce the number of hits to the Key Vault.
If you are having too many connections, then you can use a
memory cacheand set the caching to a certain time.Memory Cache:
For more information, please see the below MS Docs.
Azure Key Vault service limits
Azure Key Vault throttling