Table of Contents

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

Provider string

The provider name the served rate is attributed to.

Origin RateOrigin

Whether the rate was resolved directly by a provider or served from a cache.

Backend string

The runtime identity of the cache backend that served the request, or null for a rate resolved directly by a provider.

CachedAtUtc DateTimeOffset?

The UTC instant the served data was cached, or null for a rate resolved directly by a provider.

Age TimeSpan?

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.

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

TimeSpan?

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

string

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

DateTimeOffset?

Origin

Whether the rate was resolved directly by a provider or served from a cache.

public RateOrigin Origin { get; init; }

Property Value

RateOrigin

Provider

The provider name the served rate is attributed to.

public string Provider { get; init; }

Property Value

string

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

Provider string
Origin RateOrigin
Backend string
CachedAtUtc DateTimeOffset?
Age TimeSpan?

Equals(RateProvenance)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(RateProvenance other)

Parameters

other RateProvenance

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

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

provider string

The provider name the rate is attributed to.

backend string

The runtime identity of the cache backend that served the request.

cachedAtUtc DateTimeOffset?

The UTC instant the served data was cached, or null when no cached row backs the serve.

asOf DateTimeOffset

The lookup instant against which the age is derived.

Returns

RateProvenance

An RateProvenance with Origin set to Cache, carrying cachedAtUtc and the derived age, or no age when cachedAtUtc is 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

provider string

The 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

provider string

The provider name the rate is attributed to.

backend string

The runtime identity of the cache backend that handled the miss.

Returns

RateProvenance

An RateProvenance with Origin set to Live, carrying backend but 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

left RateProvenance
right RateProvenance

Returns

bool

operator !=(RateProvenance, RateProvenance)

public static bool operator !=(RateProvenance left, RateProvenance right)

Parameters

left RateProvenance
right RateProvenance

Returns

bool

Applies to

ProductVersions
.NET8, 10