FileRateCacheBase<TOptions> Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates.Caching
- Assembly
- Bodu.Financial.ExchangeRates.Caching.dll
- Package
- Bodu.Financial.ExchangeRates.Caching 1.0.0
- Source
- FileRateCacheBase{T}.cs
Provides the file-storage mechanism for an IRateCache: layout-driven directory and file-name resolution, optional date partitioning, and best-effort file read and write. Derived types supply only the serialization format.
public abstract class FileRateCacheBase<TOptions> : RateCacheBase<TOptions>, IFileRateCache, IRateCache where TOptions : FileRateCacheOptions
Type Parameters
TOptionsThe file-cache options type carrying the bound provider, storage directory, and file layout.
- Inheritance
-
RateCacheBase<TOptions>FileRateCacheBase<TOptions>
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
A cache instance is bound to one provider, and the Layout decides where each pair's rows are stored: a single file per pair (the default), or - when the layout is partitioned - one file per calendar period under a per-pair folder. Reads and writes are best-effort: any IOException or UnauthorizedAccessException surfaces as an empty read result or a skipped write, so a storage problem never breaks rate retrieval. Derived types are expected to treat malformed content the same way by returning an empty list from Deserialize(string, string).
For a partitioned layout a pair's rows are split across files by their observation date, and a recorded coverage window is split at partition boundaries so each file carries only the coverage for its own period; a read concatenates every partition file in the pair's folder and the shared cache rules re-merge the halves, so the split is lossless.
Constructors
FileRateCacheBase(TOptions, TimeProvider?, ILogger?)
Initializes a new instance of the FileRateCacheBase<TOptions> class.
protected FileRateCacheBase(TOptions options, TimeProvider? timeProvider = null, ILogger? logger = null)
Parameters
optionsTOptionsThe file-cache options selecting the bound provider, storage directory, and layout.
timeProviderTimeProviderThe time source the swallowed-failure warning rate-limiting is measured against, or null to use System.
loggerILoggerThe logger that receives a rate-limited warning when a best-effort storage failure is swallowed, or null to disable that reporting.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- ArgumentException
Thrown when
optionsfails validation.
Properties
CacheDirectory
Gets the directory in which cached rate files are stored.
public string CacheDirectory { get; }
Property Value
- string
The absolute or relative cache directory path.
FileExtension
Gets the file extension, including the leading period, applied to cached rate files.
protected abstract string FileExtension { get; }
Property Value
- string
The file extension used by the serialization format, for example
.toml.
Methods
ResolveDirectory(CurrencyPair)
Resolves the directory that holds the supplied pair's cache file or files for this cache's provider.
public string ResolveDirectory(CurrencyPair pair)
Parameters
pairCurrencyPairThe currency pair.
Returns
- string
The directory the pair's rates are stored in.
ResolveFilePath(CurrencyPair)
Resolves the full path of the single file that backs the supplied pair for this cache's provider.
public string ResolveFilePath(CurrencyPair pair)
Parameters
pairCurrencyPairThe currency pair.
Returns
- string
The resolved file path the pair's rates are read from and written to.
Exceptions
- InvalidOperationException
Thrown when the cache uses a partitioned layout, where a pair has no single backing file; use ResolveDirectory(CurrencyPair) or ResolvePartitionPath(CurrencyPair, DateOnly) instead.
ResolvePartitionPath(CurrencyPair, DateOnly)
Resolves the full path of the file that backs the supplied pair's rates for the partition containing
date.
public string ResolvePartitionPath(CurrencyPair pair, DateOnly date)
Parameters
pairCurrencyPairThe currency pair.
dateDateOnlyA date within the partition whose file is required.
Returns
- string
The resolved partition file path. For a single-file layout this is the pair's one file regardless of
date.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |