53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace StellaOps.Provcache.Api;
|
|
|
|
public static partial class ProvcacheEndpointExtensions
|
|
{
|
|
/// <summary>
|
|
/// GET /v1/provcache/{veriKey}
|
|
/// </summary>
|
|
private static async Task<IResult> GetByVeriKeyAsync(
|
|
string veriKey,
|
|
bool? bypassCache,
|
|
IProvcacheService provcacheService,
|
|
ILogger<ProvcacheApiEndpoints> logger,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
logger.LogDebug("GET /v1/provcache/{VeriKey}", veriKey);
|
|
|
|
try
|
|
{
|
|
var result = await provcacheService.GetAsync(veriKey, bypassCache ?? false, cancellationToken);
|
|
|
|
return result.Status switch
|
|
{
|
|
ProvcacheResultStatus.CacheHit => Results.Ok(new ProvcacheGetResponse
|
|
{
|
|
VeriKey = result.Entry!.VeriKey,
|
|
Entry = result.Entry,
|
|
Source = result.Source,
|
|
ElapsedMs = result.ElapsedMs,
|
|
Status = "hit"
|
|
}),
|
|
ProvcacheResultStatus.Bypassed => Results.Ok(new ProvcacheGetResponse
|
|
{
|
|
VeriKey = veriKey,
|
|
Entry = null,
|
|
Source = null,
|
|
ElapsedMs = result.ElapsedMs,
|
|
Status = "bypassed"
|
|
}),
|
|
ProvcacheResultStatus.Expired => Results.StatusCode(StatusCodes.Status410Gone),
|
|
_ => Results.NoContent()
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Error getting cache entry for VeriKey {VeriKey}", veriKey);
|
|
return InternalError("Cache lookup failed");
|
|
}
|
|
}
|
|
}
|