RateCacheFileLayout Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates.Caching
- Assembly
- Bodu.Financial.ExchangeRates.Caching.dll
- Package
- Bodu.Financial.ExchangeRates.Caching 1.0.0
- Source
- RateCacheFileLayout.cs
Describes where a file-backed exchange-rate cache stores a currency pair's rows: the folder that holds the pair's file or files, the name of each file, and - through its PartitionStrategy - whether the rows are split across files by date.
public sealed class RateCacheFileLayout
- Inheritance
-
RateCacheFileLayout
- Inherited Members
- Extension Methods
Remarks
A layout combines three decisions: the PartitionStrategy (single file, or one file per year, month,
day, or custom period), the directory each pair's files live in, and the name of each file. The built-in
SingleFile layout reproduces the default
<root>/<provider>/<From><To>.ext layout; Yearly,
Monthly, and Daily isolate each pair in its own folder and name the per-period files
by partition key, for example <root>/<provider>/AUDUSD/2023-01.toml.
Use Create(RateCachePartitionStrategy, Func<RateCacheDirectoryContext, string>?, Func<RateCacheFileContext, string>?) to build a custom layout from a partition strategy and optional directory and file-name delegates. A partitioned layout must isolate each pair's files in a directory that holds no other pair, because the cache discovers a pair's partitions by enumerating that directory; a custom directory delegate that shares a folder across pairs must therefore encode the pair in the file name to keep them distinct.
Properties
Daily
Gets the layout that isolates each pair in its own folder and splits its rows into one file per calendar day.
public static RateCacheFileLayout Daily { get; }
Property Value
- RateCacheFileLayout
The daily partitioned layout.
IsPartitioned
Gets a value indicating whether the layout splits a pair's rows across multiple files.
public bool IsPartitioned { get; }
Property Value
Monthly
Gets the layout that isolates each pair in its own folder and splits its rows into one file per calendar month.
public static RateCacheFileLayout Monthly { get; }
Property Value
- RateCacheFileLayout
The monthly partitioned layout.
PartitionStrategy
Gets the strategy deciding how a pair's rows are split across files by date.
public RateCachePartitionStrategy PartitionStrategy { get; }
Property Value
- RateCachePartitionStrategy
The partition strategy; Single for a single-file layout.
SingleFile
Gets the layout that stores a pair's whole history in one file under a per-provider folder, reproducing the
default <root>/<provider>/<From><To>.ext layout.
public static RateCacheFileLayout SingleFile { get; }
Property Value
- RateCacheFileLayout
The single-file layout.
Yearly
Gets the layout that isolates each pair in its own folder and splits its rows into one file per calendar year.
public static RateCacheFileLayout Yearly { get; }
Property Value
- RateCacheFileLayout
The yearly partitioned layout.
Methods
Create(RateCachePartitionStrategy, Func<RateCacheDirectoryContext, string>?, Func<RateCacheFileContext, string>?)
Creates a custom layout from a partition strategy and optional directory and file-name delegates.
public static RateCacheFileLayout Create(RateCachePartitionStrategy partitionStrategy, Func<RateCacheDirectoryContext, string>? directory = null, Func<RateCacheFileContext, string>? fileName = null)
Parameters
partitionStrategyRateCachePartitionStrategyThe strategy deciding how a pair is split across files by date.
directoryFunc<RateCacheDirectoryContext, string>An optional delegate resolving the directory that holds a pair's file or files. When null, a default is used:
<root>/<provider>for a single-file strategy, or<root>/<provider>/<From><To>for a partitioned strategy.fileNameFunc<RateCacheFileContext, string>An optional delegate resolving the name of a single cache file. When null, a default is used:
<From><To>.extfor a single-file strategy, or<partitionKey>.extfor a partitioned strategy.
Returns
- RateCacheFileLayout
A layout driven by the supplied strategy and delegates.
Exceptions
- ArgumentNullException
Thrown when
partitionStrategyis null.
ResolveDirectory(string, string, CurrencyPair)
Resolves the directory that holds the supplied pair's file or files.
public string ResolveDirectory(string root, string provider, CurrencyPair pair)
Parameters
rootstringThe resolved cache root directory.
providerstringThe provider the cache is bound to.
pairCurrencyPairThe currency pair.
Returns
- string
The directory the pair's file or files are stored in.
ResolveFileName(string, CurrencyPair, string, string)
Resolves the name of the file that holds the supplied pair and partition key.
public string ResolveFileName(string provider, CurrencyPair pair, string partitionKey, string fileExtension)
Parameters
providerstringThe provider the cache is bound to.
pairCurrencyPairThe currency pair.
partitionKeystringThe partition key, or the empty string for a single-file layout.
fileExtensionstringThe file extension, including the leading period.
Returns
- string
The file name, without directory.
Sanitize(string)
Maps a path segment to a safe form by replacing characters that are illegal in a file name with an underscore.
public static string Sanitize(string segment)
Parameters
segmentstringThe segment to sanitize.
Returns
- string
The segment with any illegal characters replaced by an underscore.
Exceptions
- ArgumentNullException
Thrown when
segmentis null.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |