Skip to content

Commit

Permalink
Packages update. Using Locker<T> from Impworks.Utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
impworks committed May 20, 2024
1 parent c0f9822 commit f47cff8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
13 changes: 4 additions & 9 deletions src/Isotope/Isotope/Code/Services/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Isotope.Code.Utils;
using Impworks.Utils.Tasks;
using Newtonsoft.Json;

namespace Isotope.Code.Services;
Expand Down Expand Up @@ -50,21 +50,16 @@ public CacheService()
public async Task<T> GetOrAddAsync<T>(string id, Func<Task<T>> getter)
{
var key = (typeof(T), id);
await _locks.WaitAsync(key, _cts.Token);
try
using (await _locks.AcquireAsync(key, _cts.Token))
{
if (_cache.ContainsKey(key))
return JsonConvert.DeserializeObject<T>(_cache[key], _jsonSettings);
if (_cache.TryGetValue(key, out var value))
return JsonConvert.DeserializeObject<T>(value, _jsonSettings);

var result = await getter();
_cache.TryAdd(key, JsonConvert.SerializeObject(result, _jsonSettings));

return result;
}
finally
{
_locks.Release(key);
}
}

/// <summary>
Expand Down
39 changes: 0 additions & 39 deletions src/Isotope/Isotope/Code/Utils/Locker.cs

This file was deleted.

16 changes: 8 additions & 8 deletions src/Isotope/Isotope/Isotope.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Impworks.Utils" Version="1.0.53" />
<PackageReference Include="Impworks.Utils" Version="1.0.54" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="Mapster.EFCore" Version="5.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
</ItemGroup>

Expand Down

0 comments on commit f47cff8

Please sign in to comment.