Table of Contents

FileSystemRbaWorkbookCache Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.Rba.dll
Package
Bodu.Financial.ExchangeRates.Rba 0.7.1
Source
FileSystemRbaWorkbookCache.cs

An IByteCache<TKey> that persists downloaded RBA workbooks as files in a cache directory, keyed by the era workbook that produced them.

public sealed class FileSystemRbaWorkbookCache : FileSystemByteCache<RbaEraWorkbook>, IByteCache<RbaEraWorkbook>
Inheritance
FileSystemRbaWorkbookCache
Implements
Inherited Members
Extension Methods

Remarks

Each era is stored under its file name in the cache directory; the file's last-write time serves as the freshness timestamp. Immutable eras are served from the cache regardless of age, while the open-ended current era is treated as stale once it exceeds the supplied refresh interval, forcing a re-download.

The cache is best-effort: any I/O failure while reading is reported as a miss, and any failure while writing is swallowed, so a cache problem never breaks rate retrieval.

Constructors

FileSystemRbaWorkbookCache(string?, ILogger?)

Initializes a new instance of the FileSystemRbaWorkbookCache class.

public FileSystemRbaWorkbookCache(string? directory, ILogger? logger = null)

Parameters

directory string

The cache directory. When null or empty, a bodu-rba folder under the system temporary path is used.

logger ILogger

The logger that receives a warning when a best-effort file-system failure is swallowed, or null to disable that reporting.

Methods

GetFileName(RbaEraWorkbook)

Derives the cache file name for a key.

protected override string GetFileName(RbaEraWorkbook key)

Parameters

key RbaEraWorkbook

The download unit to name.

Returns

string

The cache file name.

Exceptions

ArgumentNullException

key is null.

IsFresh(RbaEraWorkbook, TimeSpan, TimeSpan)

Determines whether a cached file of the supplied age is still fresh for a key.

protected override bool IsFresh(RbaEraWorkbook key, TimeSpan age, TimeSpan refreshInterval)

Parameters

key RbaEraWorkbook

The download unit the file was cached for.

age TimeSpan

The elapsed time since the file was last written.

refreshInterval TimeSpan

The maximum age a cached file may reach before it is treated as stale.

Returns

bool

true when the file may still be served; otherwise false. The default treats a file as fresh while its age does not exceed refreshInterval.

Remarks

The open-ended current era expires on the refresh interval; fixed eras are immutable and never expire.

Exceptions

ArgumentNullException

key is null.

Applies to

ProductVersions
.NET8, 10