Table of Contents

RateCachePartitionStrategy Class

Definition

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

Decides how a pair's cached rows are split across files by date: a single file for the whole pair, or one file per calendar year, month, or day, or a caller-supplied scheme.

public sealed class RateCachePartitionStrategy
Inheritance
RateCachePartitionStrategy
Inherited Members
Extension Methods

Remarks

A strategy maps each rate's Date to a path-safe partition key (the file name stem) and reports the inclusive date range that key spans. The file cache uses the key to route each row to its file and the range to split a recorded coverage window at partition boundaries, so a window that crosses, say, a month boundary is stored as one sub-window per month and re-merged losslessly on read.

Use the built-in Single, Yearly, Monthly, and Daily strategies, or Custom(Func<DateOnly, string>, Func<DateOnly, (DateOnly Start, DateOnly End)>) to supply your own keying and ranging - for example fortnightly or fiscal-quarter partitions.

Properties

Daily

Gets the strategy that splits a pair into one file per calendar day, keyed yyyy-MM-dd.

public static RateCachePartitionStrategy Daily { get; }

Property Value

RateCachePartitionStrategy

The daily partition strategy.

IsPartitioned

Gets a value indicating whether the strategy splits a pair's rows across multiple files.

public bool IsPartitioned { get; }

Property Value

bool

true when rows are partitioned into per-key files; false when the whole pair lives in one file.

Monthly

Gets the strategy that splits a pair into one file per calendar month, keyed yyyy-MM.

public static RateCachePartitionStrategy Monthly { get; }

Property Value

RateCachePartitionStrategy

The monthly partition strategy.

Single

Gets the strategy that keeps every row for a pair in a single file.

public static RateCachePartitionStrategy Single { get; }

Property Value

RateCachePartitionStrategy

The single-file strategy.

Yearly

Gets the strategy that splits a pair into one file per calendar year, keyed yyyy.

public static RateCachePartitionStrategy Yearly { get; }

Property Value

RateCachePartitionStrategy

The yearly partition strategy.

Methods

Custom(Func<DateOnly, string>, Func<DateOnly, (DateOnly Start, DateOnly End)>)

Creates a custom partition strategy from a key selector and a matching range selector.

public static RateCachePartitionStrategy Custom(Func<DateOnly, string> keySelector, Func<DateOnly, (DateOnly Start, DateOnly End)> rangeSelector)

Parameters

keySelector Func<DateOnly, string>

Maps a date to its path-safe partition key.

rangeSelector Func<DateOnly, (DateOnly Start, DateOnly End)>

Maps a date to the inclusive date range its partition spans.

Returns

RateCachePartitionStrategy

A partition strategy driven by the supplied delegates.

Remarks

The two delegates must agree: every date the rangeSelector reports for a partition must map to the same key under keySelector, otherwise coverage windows split at the wrong boundaries. The returned key must be a valid file-name stem; the file cache does not sanitize it.

Exceptions

ArgumentNullException

Thrown when keySelector or rangeSelector is null.

GetPartitionKey(DateOnly)

Returns the partition key for the file that holds rows observed on date.

public string GetPartitionKey(DateOnly date)

Parameters

date DateOnly

The observation date to map.

Returns

string

The partition key - a path-safe file-name stem, or the empty string for Single.

GetPartitionRange(DateOnly)

Returns the inclusive date range spanned by the partition that contains date.

public (DateOnly Start, DateOnly End) GetPartitionRange(DateOnly date)

Parameters

date DateOnly

A date within the partition.

Returns

(DateOnly StartDate, DateOnly EndDate)

The inclusive (Start, End) range of the containing partition.

Applies to

ProductVersions
.NET8, 10