diff --git a/PermissionsService/Services/PermissionsStore.cs b/PermissionsService/Services/PermissionsStore.cs index 2d5a003c9..bc2ccbe15 100644 --- a/PermissionsService/Services/PermissionsStore.cs +++ b/PermissionsService/Services/PermissionsStore.cs @@ -46,6 +46,8 @@ public class PermissionsStore : IPermissionsStore private readonly string _scopesInformation; private readonly int _defaultRefreshTimeInHours; // life span of the in-memory cache private const string DefaultLocale = "en-US"; // default locale language + private static readonly AsyncNonKeyedLocker _permissionDataLocker = new(); + private static readonly AsyncNonKeyedLocker _permissionsDocumentLocker = new(); private static readonly AsyncKeyedLocker _asyncKeyedLocker = new(); private const string Delegated = "Delegated"; private const string Application = "Application"; @@ -90,7 +92,7 @@ public PermissionsStore(IConfiguration configuration, IHttpClientUtility httpCli private async Task GetPermissionsDataAsync() { - using(await _asyncKeyedLocker.LockAsync("PermissionData")) + using(await _permissionDataLocker.LockAsync()) { return await _cache.GetOrCreateAsync("PermissionsData", async entry => { @@ -103,7 +105,7 @@ private async Task GetPermissionsDataAsync() private async Task LoadDocumentAsync() { - using(await _asyncKeyedLocker.LockAsync("PermissionsDocument")) + using(await _permissionsDocumentLocker.LockAsync()) { return await _cache.GetOrCreateAsync("PermissionsDocument", async entry => { @@ -206,10 +208,10 @@ private async Task>> G SeverityLevel.Information, _permissionsTraceProperties); - // making sure only a single thread at a time access the cache + // making sure only a single thread at a time access the cache per locale // when already seeded, lock will resolve fast and access the cache // when not seeded, lock will resolve slow for all other threads and seed the cache on the first thread - using (await _asyncKeyedLocker.LockAsync("scopes")) + using (await _asyncKeyedLocker.LockAsync(locale)) { var scopesInformationDictionary = await _cache.GetOrCreateAsync($"ScopesInfoList_{locale}", async cacheEntry => { diff --git a/SamplesService/Services/SamplesStore.cs b/SamplesService/Services/SamplesStore.cs index 863770669..ae6e29ec9 100644 --- a/SamplesService/Services/SamplesStore.cs +++ b/SamplesService/Services/SamplesStore.cs @@ -68,10 +68,10 @@ public async Task FetchSampleQueriesListAsync(string locale) string sourceMsg = $"Return sample queries list for locale '{locale}' from in-memory cache '{locale}'"; - // making sure only a single thread at a time access the cache + // making sure only a single thread at a time access the cache per locale // when already seeded, lock will resolve fast and access the cache // when not seeded, lock will resolve slow for all other threads and seed the cache on the first thread - using (await _asyncKeyedLocker.LockAsync("samples")) + using (await _asyncKeyedLocker.LockAsync(locale)) { // Fetch cached sample queries var sampleQueriesList = await _samplesCache.GetOrCreateAsync(locale, async cacheEntry =>