FileSystemImfReportCache Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Imf.dll
- Package
- Bodu.Financial.ExchangeRates.Imf 0.7.1
An IImfReportCache that persists downloaded IMF monthly reports as files in a cache directory.
public sealed class FileSystemImfReportCache : FileSystemByteCache<ImfReportMonth>, IByteCache<ImfReportMonth>, IImfReportCache
- Inheritance
-
FileSystemImfReportCache
- Implements
- Inherited Members
- Extension Methods
Remarks
Each report is stored under its month's file name in the cache directory; the file's last-write time serves as the freshness timestamp. A report for a month strictly before the current UTC month is immutable and is therefore always served regardless of its age; the report for the current month 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
FileSystemImfReportCache(string?, ILogger?)
Initializes a new instance of the FileSystemImfReportCache class.
public FileSystemImfReportCache(string? directory, ILogger? logger = null)
Parameters
Methods
GetFileName(ImfReportMonth)
Derives the cache file name for a key.
protected override string GetFileName(ImfReportMonth key)
Parameters
keyImfReportMonthThe download unit to name.
Returns
- string
The cache file name.
Exceptions
- ArgumentNullException
keyis null.
IsFresh(ImfReportMonth, TimeSpan, TimeSpan)
Determines whether a cached file of the supplied age is still fresh for a key.
protected override bool IsFresh(ImfReportMonth key, TimeSpan age, TimeSpan refreshInterval)
Parameters
keyImfReportMonthThe download unit the file was cached for.
ageTimeSpanThe elapsed time since the file was last written.
refreshIntervalTimeSpanThe 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
A report for a month strictly before the current UTC month is closed and immutable, so it is always fresh regardless of its file age; only the current (still-accumulating) month is subject to the refresh interval.
Exceptions
- ArgumentNullException
keyis null.
Store(ImfReportMonth, byte[])
Stores the bytes for a report month, replacing any existing entry.
public void Store(ImfReportMonth month, byte[] bytes)
Parameters
monthImfReportMonthThe report month whose file is being cached.
bytesbyte[]The report bytes to store.
Remarks
Intentionally hides the unguarded base member so calls through this type (and through IImfReportCache) validate their arguments before touching the file system.
TryGet(ImfReportMonth, TimeSpan, out byte[])
Attempts to retrieve the cached bytes for a report month.
public bool TryGet(ImfReportMonth month, TimeSpan refreshInterval, out byte[] bytes)
Parameters
monthImfReportMonthThe report month whose file is requested.
refreshIntervalTimeSpanThe maximum age at which a current-month report is still considered fresh.
bytesbyte[]When this method returns true, the cached report bytes; otherwise null.
Returns
Remarks
Intentionally hides the unguarded base member so calls through this type (and through IImfReportCache) validate their arguments before touching the file system.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |