namespace StellaOps.Provcache; /// /// Result of a cache service lookup. /// public sealed record ProvcacheServiceResult { /// /// The cache result status. /// public required ProvcacheResultStatus Status { get; init; } /// /// The cache entry if found. /// public ProvcacheEntry? Entry { get; init; } /// /// Whether the result came from cache (true) or needs computation (false). /// public bool WasCached => Status == ProvcacheResultStatus.CacheHit; /// /// Source of the cache hit for diagnostics. /// public string? Source { get; init; } /// /// Time taken for the lookup in milliseconds. /// public double ElapsedMs { get; init; } /// /// Creates a cache hit result. /// public static ProvcacheServiceResult Hit(ProvcacheEntry entry, string source, double elapsedMs) => new() { Status = ProvcacheResultStatus.CacheHit, Entry = entry, Source = source, ElapsedMs = elapsedMs }; /// /// Creates a cache miss result. /// public static ProvcacheServiceResult Miss(double elapsedMs) => new() { Status = ProvcacheResultStatus.CacheMiss, Entry = null, Source = null, ElapsedMs = elapsedMs }; /// /// Creates a bypassed result (cache was skipped). /// public static ProvcacheServiceResult Bypassed() => new() { Status = ProvcacheResultStatus.Bypassed, Entry = null, Source = null, ElapsedMs = 0 }; /// /// Creates an expired result. /// public static ProvcacheServiceResult Expired(ProvcacheEntry entry, double elapsedMs) => new() { Status = ProvcacheResultStatus.Expired, Entry = entry, Source = "expired", ElapsedMs = elapsedMs }; }