Skip to content

Commit

Permalink
Made use of AsyncNonKeyedLocker; bumped AsyncKeyedLock library.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Apr 21, 2024
1 parent 3b53c5e commit 0875883
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="AsyncKeyedLock" Version="[6.3.4,)"/>
<PackageReference Include="AsyncKeyedLock" Version="[6.4.1,)"/>
<None Include="../../README.md" Link="README.md" Pack="true" PackagePath="/" Visible="false"/>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using AsyncKeyedLock;
using CacheManager.Core;
using EasyCaching.Core.Configurations;
using EasyCaching.InMemory;
Expand Down Expand Up @@ -54,7 +54,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s

public static class EFServiceProvider
{
private static readonly SemaphoreSlim _semaphoreSlim = new(1, 1);
private static readonly AsyncNonKeyedLocker _locker = new();

public static IEFCacheServiceProvider GetCacheServiceProvider(TestCacheProvider provider)
{
Expand Down Expand Up @@ -377,8 +377,7 @@ public static void RunInContext(
bool cacheAllQueries,
params Action<ApplicationDbContext, DebugLoggerProvider>[] actions)
{
_semaphoreSlim.Wait();
try
using (_locker.Lock())
{
var serviceProvider = GetConfiguredContextServiceProvider(cacheProvider, logLevel, cacheAllQueries);
var cacheServiceProvider = serviceProvider.GetRequiredService<IEFCacheServiceProvider>();
Expand All @@ -394,10 +393,6 @@ public static void RunInContext(
}
}
}
finally
{
_semaphoreSlim.Release();
}
}

public static async Task RunInContextAsync(
Expand All @@ -406,8 +401,7 @@ public static async Task RunInContextAsync(
bool cacheAllQueries,
params Func<ApplicationDbContext, DebugLoggerProvider, Task>[] actions)
{
await _semaphoreSlim.WaitAsync();
try
using (await _locker.LockAsync())
{
var serviceProvider = GetConfiguredContextServiceProvider(cacheProvider, logLevel, cacheAllQueries);
var cacheServiceProvider = serviceProvider.GetRequiredService<IEFCacheServiceProvider>();
Expand All @@ -424,10 +418,6 @@ await action(context,
}
}
}
finally
{
_semaphoreSlim.Release();
}
}

public static void ExecuteInParallel(Action test, int count = 40)
Expand Down

0 comments on commit 0875883

Please sign in to comment.