Table of Contents

TomlFileRateCache Class

Definition

Namespace
Bodu.Financial.ExchangeRates.Caching
Assembly
Bodu.Financial.ExchangeRates.Caching.dll
Package
Bodu.Financial.ExchangeRates.Caching 1.0.0
Source
TomlFileRateCache.cs

An IRateCache that persists a provider's rates as TOML files, one file per currency pair (or, under a partitioned layout, per pair and calendar period).

public sealed class TomlFileRateCache : FileRateCacheBase<FileRateCacheOptions>, IFileRateCache, IRateCache
Inheritance
TomlFileRateCache
Implements
Inherited Members
Extension Methods

Examples

A cache bound to provider RBA stores the AUD/USD pair as <directory>/RBA/AUDUSD.toml with the self-describing header, one table per dated rate, and one table per fetched window:

Provider = "RBA"
From = "AUD"
To = "USD"

[[Entries]]
Date = 2023-01-03
Rate = "0.5000"
CachedAtUtc = 2023-01-04T09:15:00+00:00
ObservedAtUtc = 2023-01-03T16:00:00+00:00

[[Entries]]
Date = 2023-01-06
Rate = "0.5100"
CachedAtUtc = 2023-01-04T09:15:00+00:00
ObservedAtUtc = 2023-01-06T16:00:00+00:00

[[Coverage]]
Start = 2023-01-03
End = 2023-01-06
FetchedAtUtc = 2023-01-04T09:15:00+00:00

Remarks

Each file records the bound Provider and the pair's From and To currency codes as top-level keys - making the file self-describing rather than identified only by its name and folder - followed by a TOML array of tables under Entries, one table per dated rate, and a second array of tables under Coverage, one table per recorded fetch window. Decimal rates are written as quoted strings (String) so the full precision and scale round-trips exactly; dates and instants use TOML's native RFC 3339 forms.

A file written before coverage was tracked has no [[Coverage]] section; it deserializes to its rate rows with empty coverage and no error, so older caches remain readable and simply refetch ranges until coverage is recorded. Likewise, an entry written before the upstream fetch instant was tracked has no ObservedAtUtc key and deserializes that field to null, and a file written before the self-describing header was added has no Provider/From/To keys.

Files are laid out by the configured Layout - by default a single file per pair under a per-provider subdirectory, or one file per calendar period when a partitioned layout is selected. Malformed content is treated as an empty result, and all file-level resilience - including atomic temp-and-move writes - is provided by FileRateCacheBase<TOptions>.

Constructors

TomlFileRateCache(FileRateCacheOptions, TimeProvider?, ILogger?)

Initializes a new instance of the TomlFileRateCache class.

public TomlFileRateCache(FileRateCacheOptions options, TimeProvider? timeProvider = null, ILogger? logger = null)

Parameters

options FileRateCacheOptions

The file-cache options that select the bound provider and storage directory.

timeProvider TimeProvider

The time source the swallowed-failure warning rate-limiting is measured against, or null to use System.

logger ILogger

The logger that receives a rate-limited warning when a best-effort storage failure is swallowed, or null to disable that reporting.

Exceptions

ArgumentNullException

Thrown when options is null.

ArgumentException

Thrown when options fails validation.

Properties

FileExtension

Gets the file extension, including the leading period, applied to cached rate files.

protected override string FileExtension { get; }

Property Value

string

The file extension used by the serialization format, for example .toml.

Applies to

ProductVersions
.NET8, 10