stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StellaOps.Provcache;
|
||||
|
||||
public sealed partial class ProvcacheService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<ProvcacheEntry> GetOrComputeAsync(
|
||||
string veriKey,
|
||||
Func<CancellationToken, Task<ProvcacheEntry>> factory,
|
||||
bool bypassCache = false,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(veriKey);
|
||||
ArgumentNullException.ThrowIfNull(factory);
|
||||
|
||||
if (!bypassCache || !_options.AllowCacheBypass)
|
||||
{
|
||||
var result = await GetAsync(veriKey, bypassCache: false, cancellationToken).ConfigureAwait(false);
|
||||
if (result.WasCached && result.Entry is not null)
|
||||
{
|
||||
return result.Entry;
|
||||
}
|
||||
}
|
||||
|
||||
var entry = await factory(cancellationToken).ConfigureAwait(false);
|
||||
await SetAsync(entry, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user