Moves the six backend projects on disk into Core/ and Hosts/ subfolders, matching the solution folders already defined in Musify.slnx, so the file explorer reflects the same layout as the solution: backend/Core/Musify.Domain backend/Core/Musify.Application backend/Core/Musify.Infrastructure backend/Hosts/Musify.Api backend/Hosts/Musify.Worker backend/Hosts/Musify.StreamingGateway Updates every reference to the old paths: ProjectReference entries in Musify.Api.csproj and Musify.Worker.csproj, the three Dockerfiles, deploy/scripts/migrate.ps1|sh, deploy/zitadel/provision.ps1, deploy/up.ps1, deploy/README.md and docs/development.md. Also fixes a stale Dockerfile comment pointing at a compose file that no longer exists. Verified with `dotnet build Musify.slnx` against the new layout.
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System.Collections.Concurrent;
|
|
using ErrorOr;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace Musify.Infrastructure.Services
|
|
{
|
|
public sealed class SingleFlightCache(IMemoryCache cache)
|
|
{
|
|
private readonly ConcurrentDictionary<string, object> inFlight = new();
|
|
|
|
public async Task<ErrorOr<TValue>> GetOrCreateAsync<TValue>(
|
|
string key,
|
|
TimeSpan duration,
|
|
Func<Task<ErrorOr<TValue>>> factory)
|
|
{
|
|
if (duration <= TimeSpan.Zero)
|
|
return await factory();
|
|
|
|
if (cache.TryGetValue(key, out TValue? cached) && cached is not null)
|
|
return cached;
|
|
|
|
var pending = (Lazy<Task<ErrorOr<TValue>>>)inFlight.GetOrAdd(
|
|
key,
|
|
_ => new Lazy<Task<ErrorOr<TValue>>>(factory));
|
|
|
|
try
|
|
{
|
|
var result = await pending.Value;
|
|
|
|
if (!result.IsError)
|
|
cache.Set(key, result.Value, duration);
|
|
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
inFlight.TryRemove(key, out _);
|
|
}
|
|
}
|
|
}
|
|
}
|