Table of Contents

InMemoryRateCache Class

Definition

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

An IRateCache that stores a single provider's rates in memory for the lifetime of the instance, expiring them through the same freshness mechanism as the file caches.

public sealed class InMemoryRateCache : RateCacheBase<RateCacheOptions>, IRateCache
Inheritance
InMemoryRateCache
Implements
Inherited Members
Extension Methods

Examples

// An in-memory caching provider: read-through caching with no on-disk files.
var options = new CachingRateOptions { DefaultExpiry = TimeSpan.FromMinutes(15) };
IDatedRateProvider cached = new CachingRateProvider(rba, new InMemoryRateCache("RBA"), options);

Remarks

Rates expire by caching duration rather than by storage: the shared RateCacheBase<TOptions> filters stale rows on read and prunes them on write, so a cached rate is served only while it remains fresh under the duration supplied by the caching provider (see DefaultExpiry and ProviderExpiry). Nothing is persisted, so the cache starts empty on each process and is a drop-in alternative to TomlFileRateCache when on-disk files are unwanted.

Reads and writes are individually thread-safe. As with every IRateCache, a concurrent store-after-store for the same pair resolves last-write-wins, which is acceptable for a best-effort cache.

Constructors

InMemoryRateCache(RateCacheOptions)

Initializes a new instance of the InMemoryRateCache class.

public InMemoryRateCache(RateCacheOptions options)

Parameters

options RateCacheOptions

The options carrying the bound provider.

Exceptions

ArgumentNullException

Thrown when options is null.

ArgumentException

Thrown when options fails validation.

InMemoryRateCache(string)

Initializes a new instance of the InMemoryRateCache class bound to a provider name.

public InMemoryRateCache(string provider)

Parameters

provider string

The provider the cache stores rates for.

Exceptions

ArgumentNullException

Thrown when provider is null.

ArgumentException

Thrown when provider is empty or white space.

Applies to

ProductVersions
.NET8, 10