Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made use of AsyncNonKeyedLocker; bumped AsyncKeyedLock library. #239

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading