Table of Contents

RateCacheOptions Class

Definition

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

Provides the storage-agnostic options shared by every IRateCache: the single provider a cache instance is bound to. Storage-specific option types derive from this base to add their own location settings.

public class RateCacheOptions
Inheritance
RateCacheOptions
Derived
Inherited Members
Extension Methods

Remarks

A cache instance serves exactly one provider, so the provider name is fixed here at construction rather than supplied on each call. This lets the provider identity participate in the storage layout (for example a per-provider subdirectory) without ambiguity, and keeps the IRateCache surface free of a provider argument.

Constructors

RateCacheOptions()

public RateCacheOptions()

Properties

Provider

Gets or sets the name of the provider whose rates this cache stores.

public string Provider { get; set; }

Property Value

string

The provider identifier the cache is bound to.

ThrowOnStorageFailure

Gets or sets a value indicating whether a storage read or write failure is surfaced as an exception rather than degrading to an empty read or a skipped write.

public bool ThrowOnStorageFailure { get; set; }

Property Value

bool

true to rethrow the underlying storage failure; false (the default) to keep the best-effort behaviour the IRateCache contract describes.

Remarks

The default keeps a cache fault from breaking rate retrieval, which suits most consumers. Set it for a deployment that must not run with a silently broken cache: the underlying failure then propagates from the read or write so a caller fails fast rather than trusting an empty or stale result. Argument validation always throws regardless of this setting.

ValidateStorageOnStart

Gets or sets a value indicating whether the cache eagerly probes its backing store when constructed and throws when the store is unusable, rather than deferring the discovery to the first read or write.

public bool ValidateStorageOnStart { get; set; }

Property Value

bool

true to probe the store at construction; false (the default) to skip the probe.

Remarks

The probe surfaces a misconfigured directory, an unopenable database, or an unreachable distributed cache at construction. The SQLite and distributed dependency-injection packages run this probe through their ValidateOnStart wiring, so a misconfigured store fails the host start; a cache constructed directly probes in its constructor instead. This setting is independent of ThrowOnStorageFailure: a cache can validate once at construction yet still degrade best-effort on a later transient fault, or run best-effort at construction yet fail fast on every later read or write.

Methods

TryValidate(out string?)

Attempts to validate the options without throwing, reporting the first invariant that is violated.

public virtual bool TryValidate(out string? error)

Parameters

error string

When this method returns false, a message describing the first violated invariant; otherwise null.

Returns

bool

true when every invariant holds; otherwise false.

Remarks

The dependency-injection registration wires this method into ValidateOnStart so misconfiguration fails fast at application startup. It mirrors the invariants of Validate() but returns a message rather than throwing with a ParamName. Storage-specific option types override this method to add their own invariants after invoking the base implementation.

Validate()

Validates the option values, throwing when a rule is violated.

public virtual void Validate()

Remarks

This throwing form preserves the ParamName of the offending option, which callers rely on. The dependency-injection registration instead wires TryValidate(out string?) into ValidateOnStart, which reports the same invariants without throwing.

Exceptions

ArgumentNullException

Thrown when Provider is null.

ArgumentException

Thrown when Provider is empty or white space.

Applies to

ProductVersions
.NET8, 10