Table of Contents

CachingRateProvider Class

Definition

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

A caching provider that wraps a single inner IDatedRateProvider over a single-provider IRateCache, serving fresh rates from the cache and delegating to the inner provider only on a miss.

public sealed class CachingRateProvider : CachingRateProviderBase, IDatedRateProvider, IRateProvider, IHistoricalRateProvider, IDisposable
Inheritance
CachingRateProvider
Implements
Inherited Members
Extension Methods

Examples

var options = new CachingRateOptions { DefaultExpiry = TimeSpan.FromHours(12) };

// Read-through caching over a TOML file cache (the caller picks the storage).
var fileCache = new TomlFileRateCache(
    new FileRateCacheOptions { Provider = "RBA", CacheDirectory = "/var/cache/fx" });
IDatedRateProvider cachedRba = new CachingRateProvider(rba, fileCache, options);

// Or any other IRateCache - for example an in-memory cache.
IDatedRateProvider cachedEcb = new CachingRateProvider(ecb, new InMemoryRateCache("ECB"), options);

Remarks

Use this to add read-through caching to one rate source. To group several cached sources behind a single entry point - with priority-fallback, averaging, or per-pair routing - compose them with an AggregatingRateProvider.

The provider is storage-agnostic: it does not choose or construct a cache, so the storage structure - TOML or JSON files, the on-disk layout and date partitioning, an in-memory cache, SQLite, or a distributed cache - is the caller's decision. Supply any IRateCache, already bound to its provider, to the constructor.

Constructors

CachingRateProvider(IDatedRateProvider, IRateCache, CachingRateOptions, TimeProvider?, ILogger?, bool)

Initializes a new instance of the CachingRateProvider class wrapping inner over the supplied cache.

public CachingRateProvider(IDatedRateProvider inner, IRateCache cache, CachingRateOptions options, TimeProvider? timeProvider = null, ILogger? logger = null, bool ownsInner = false)

Parameters

inner IDatedRateProvider

The inner provider consulted on a cache miss.

cache IRateCache

The single-provider cache that serves fresh rates and stores resolved observations.

options CachingRateOptions

The options carrying the caching durations and timeless-surface lookup options.

timeProvider TimeProvider

The time source used to evaluate freshness and stamp newly cached rows. null selects System.

logger ILogger

The logger that records cache diagnostics, or null to disable logging.

ownsInner bool

true to dispose inner (when it is IDisposable) as part of disposing this provider; otherwise false to leave the inner's lifetime to its owner.

Exceptions

ArgumentNullException

Thrown when inner, cache, or options is null.

ArgumentException

Thrown when options fails validation.

Properties

Inner

Gets the inner provider consulted on a cache miss.

protected override IDatedRateProvider Inner { get; }

Property Value

IDatedRateProvider

The wrapped inner provider.

Applies to

ProductVersions
.NET8, 10