RateProvenance Struct
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.0.0
- Source
- RateProvenance.cs
Captures the lineage of a single served exchange rate: the provider name it is attributed to, whether it was resolved directly by a provider or served from a cache, the cache backend that served it, and - for a cache serve - the instant the served data was cached together with the derived age at the time of the lookup.
public readonly struct RateProvenance : IEquatable<RateProvenance>
- Implements
- Inherited Members
- Extension Methods
Remarks
Every RateLookupResult carries a populated RateProvenance. A rate resolved directly by a provider reports Live with a null Backend, CachedAtUtc, and Age; a rate served from a cache reports Cache with the serving backend, the instant the data was cached, and the age it had carried at the lookup instant.
Construct instances through Live(string), Live(string, string), and FromCache(string, string, DateTimeOffset?, DateTimeOffset) rather than the positional constructor so the origin-specific invariants - a live serve carries neither a cache instant nor an age - are applied consistently.
Constructors
RateProvenance(string, RateOrigin, string?, DateTimeOffset?, TimeSpan?)
Captures the lineage of a single served exchange rate: the provider name it is attributed to, whether it was resolved directly by a provider or served from a cache, the cache backend that served it, and - for a cache serve - the instant the served data was cached together with the derived age at the time of the lookup.
public RateProvenance(string Provider, RateOrigin Origin, string? Backend, DateTimeOffset? CachedAtUtc, TimeSpan? Age)
Parameters
ProviderstringThe provider name the served rate is attributed to.
OriginRateOriginWhether the rate was resolved directly by a provider or served from a cache.
BackendstringThe runtime identity of the cache backend that served the request, or null for a rate resolved directly by a provider.
CachedAtUtcDateTimeOffset?The UTC instant the served data was cached, or null for a rate resolved directly by a provider.
AgeTimeSpan?The elapsed time between
CachedAtUtcand the lookup instant, or null for a rate resolved directly by a provider or when no cached row backs the serve.
Remarks
Every RateLookupResult carries a populated RateProvenance. A rate resolved directly by a provider reports Live with a null Backend, CachedAtUtc, and Age; a rate served from a cache reports Cache with the serving backend, the instant the data was cached, and the age it had carried at the lookup instant.
Construct instances through Live(string), Live(string, string), and FromCache(string, string, DateTimeOffset?, DateTimeOffset) rather than the positional constructor so the origin-specific invariants - a live serve carries neither a cache instant nor an age - are applied consistently.
Properties
Age
The elapsed time between CachedAtUtc and the lookup instant, or null for a
rate resolved directly by a provider or when no cached row backs the serve.
public TimeSpan? Age { get; init; }
Property Value
Backend
The runtime identity of the cache backend that served the request, or null for a rate resolved directly by a provider.
public string? Backend { get; init; }
Property Value
CachedAtUtc
The UTC instant the served data was cached, or null for a rate resolved directly by a provider.
public DateTimeOffset? CachedAtUtc { get; init; }
Property Value
Origin
Whether the rate was resolved directly by a provider or served from a cache.
public RateOrigin Origin { get; init; }
Property Value
Provider
The provider name the served rate is attributed to.
public string Provider { get; init; }
Property Value
Methods
Deconstruct(out string, out RateOrigin, out string?, out DateTimeOffset?, out TimeSpan?)
public void Deconstruct(out string Provider, out RateOrigin Origin, out string? Backend, out DateTimeOffset? CachedAtUtc, out TimeSpan? Age)
Parameters
ProviderstringOriginRateOriginBackendstringCachedAtUtcDateTimeOffset?AgeTimeSpan?
Equals(RateProvenance)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(RateProvenance other)
Parameters
otherRateProvenanceAn object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
FromCache(string, string, DateTimeOffset?, DateTimeOffset)
Creates provenance for a rate served from a cache, deriving its age from the served instant and the lookup instant.
public static RateProvenance FromCache(string provider, string backend, DateTimeOffset? cachedAtUtc, DateTimeOffset asOf)
Parameters
providerstringThe provider name the rate is attributed to.
backendstringThe runtime identity of the cache backend that served the request.
cachedAtUtcDateTimeOffset?The UTC instant the served data was cached, or null when no cached row backs the serve.
asOfDateTimeOffsetThe lookup instant against which the age is derived.
Returns
- RateProvenance
An RateProvenance with Origin set to Cache, carrying
cachedAtUtcand the derived age, or no age whencachedAtUtcis null.
Remarks
The age is clamped to Zero so a never-negative value is reported: cache freshness
tolerates a row stamped slightly ahead of asOf (a row may be written up to about a minute in
the future of the lookup clock), which would otherwise make asOf - cachedAtUtc marginally negative.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Live(string)
Creates provenance for a rate resolved directly by a provider, leaving the cache backend, cache instant, and age unset.
public static RateProvenance Live(string provider)
Parameters
providerstringThe provider name the rate is attributed to.
Returns
- RateProvenance
An RateProvenance with Origin set to Live and no backend, cache instant, or age.
Live(string, string)
Creates provenance for a rate resolved live through a cache-fronted provider's wrapped inner provider, recording the cache backend that handled the miss while leaving the cache instant and age unset.
public static RateProvenance Live(string provider, string backend)
Parameters
providerstringThe provider name the rate is attributed to.
backendstringThe runtime identity of the cache backend that handled the miss.
Returns
- RateProvenance
An RateProvenance with Origin set to Live, carrying
backendbut no cache instant or age.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator ==(RateProvenance, RateProvenance)
public static bool operator ==(RateProvenance left, RateProvenance right)
Parameters
leftRateProvenancerightRateProvenance
Returns
operator !=(RateProvenance, RateProvenance)
public static bool operator !=(RateProvenance left, RateProvenance right)
Parameters
leftRateProvenancerightRateProvenance
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |