Table of Contents

DistributedRateCacheOptions Class

Definition

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

Configures a distributed-cache-backed IRateCache: the single provider inherited from RateCacheOptions together with an optional key prefix applied to every entry the cache writes to the backing IDistributedCache.

public class DistributedRateCacheOptions : RateCacheOptions
Inheritance
DistributedRateCacheOptions
Inherited Members
Extension Methods

Remarks

The backing store is supplied by the dependency-injection container as an IDistributedCache (for example a Redis cache) rather than by these options; this type therefore carries only the bound provider and an optional KeyPrefix used to namespace the cache's entries so several applications, or several caches, can safely share one distributed store.

Freshness is supplied per call by the caching provider, so this type carries no caching duration of its own. Server-side lifetime is a separate concern: each written blob is stamped with an absolute expiration of the caching duration plus EntryExpirationMargin, so a key whose pair stops being queried self-evicts from the backing store instead of lingering forever. Set the margin to null to write entries without any server-side expiration (the pre-margin behaviour).

Constructors

DistributedRateCacheOptions()

public DistributedRateCacheOptions()

Properties

EntryExpirationMargin

Gets or sets the margin added to the caching duration when deriving each written blob's server-side absolute expiration, or null to write entries without any server-side expiration.

public TimeSpan? EntryExpirationMargin { get; set; }

Property Value

TimeSpan?

The expiration margin; defaults to one hour.

Remarks

Every entry this cache serves must already be fresh under the per-call caching duration, so an entry evicted server-side at duration + margin would in any case have been filtered on read - served results are unchanged in any normal configuration. The margin keeps the server-side lifetime comfortably behind the application-side freshness (including the shared one-minute clock-skew tolerance), so eviction never races a legitimate read.

One corner is worth knowing: a deployment that stores under one duration and later reads under a longer one (for example after raising the provider's expiry at runtime) could observe a server-side eviction where it previously saw a hit. Set the margin to null to opt out entirely and restore unbounded server-side lifetime.

KeyPrefix

Gets or sets the prefix prepended to every cache key the cache writes.

public string? KeyPrefix { get; set; }

Property Value

string

The key prefix, or null to write keys without a prefix.

Remarks

A prefix namespaces the cache's entries within a shared distributed store so that several applications, or several caches over different providers, do not collide. When set it is included verbatim at the front of every key; when unset, keys begin with the provider name.

Validation rejects only a value that is non-null but consists solely of white space. It does not constrain length or screen for control characters, so a prefix that a particular IDistributedCache backend rejects as a key is not caught here and surfaces only when the backing store is exercised.

Methods

TryValidate(out string?)

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

public override 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 override void Validate()

Exceptions

ArgumentNullException

Thrown when Provider is null.

ArgumentException

Thrown when Provider is empty or white space, or when KeyPrefix is supplied but consists only of white space.

Applies to

ProductVersions
.NET8, 10