Table of Contents

SqliteRateCacheOptions Class

Definition

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

Configures a SQLite-backed IRateCache: the provider inherited from RateCacheOptions together with the location of the SQLite database its rates and coverage windows are persisted in, and the connection-level concurrency settings applied on open.

public class SqliteRateCacheOptions : RateCacheOptions
Inheritance
SqliteRateCacheOptions
Inherited Members
Extension Methods

Remarks

The database location is supplied either as a DatabaseFilePath - the simplest form, a path to a SQLite file that is created on first use - or as a fully specified ConnectionString for advanced scenarios such as a shared in-memory database or custom connection flags. At least one must be set; ConnectionString takes precedence when both are supplied.

A single database file may be shared by several caches: each cache stores exactly one provider, and the provider is the leading column of the rate and coverage keys, so multiple single-provider caches pointed at the same file keep their series partitioned with no collisions. UseWriteAheadLogging and BusyTimeout govern how concurrent writers - multiple cache instances, or separate processes - sharing one file behave.

Expiry is not a storage concern - it is supplied per call by the caching provider - so this type carries only the storage location and connection settings in addition to the bound provider.

Constructors

SqliteRateCacheOptions()

public SqliteRateCacheOptions()

Properties

BusyTimeout

Gets or sets the time a connection waits for a held database lock to clear before reporting a busy error.

public TimeSpan BusyTimeout { get; set; }

Property Value

TimeSpan

The busy-wait duration applied as the SQLite busy_timeout pragma on every connection. The default is five seconds; Zero disables waiting, so a contended write fails immediately.

Remarks

When multiple cache instances or processes write to one shared file, a non-zero timeout lets a writer wait for a peer's transaction to commit instead of failing the write outright, which the best-effort cache would otherwise swallow as a silently dropped write.

ConnectionString

Gets or sets the full SQLite connection string used by the cache.

public string? ConnectionString { get; set; }

Property Value

string

The connection string, or null to derive one from DatabaseFilePath.

Remarks

Takes precedence over DatabaseFilePath when both are supplied, allowing scenarios such as a shared in-memory database (Data Source=name;Mode=Memory;Cache=Shared) or custom connection flags.

A supplied value is not parsed or validated when the options are constructed - only its presence is checked. A malformed or unusable connection string is therefore not rejected up front; it surfaces later at connect time, where the cache's best-effort behaviour degrades to an empty read or a skipped write rather than throwing.

DatabaseFilePath

Gets or sets the path to the SQLite database file used by the cache.

public string? DatabaseFilePath { get; set; }

Property Value

string

The database file path, or null when a full ConnectionString is supplied instead.

Remarks

When set without a ConnectionString, the cache opens the file with default connection settings, creating the file and any missing schema on first use.

UseWriteAheadLogging

Gets or sets a value indicating whether the cache enables SQLite write-ahead logging (WAL) on the database.

public bool UseWriteAheadLogging { get; set; }

Property Value

bool

true to switch a file database to WAL journal mode on open; otherwise false to leave the journal mode unchanged. The default is true.

Remarks

WAL lets readers run concurrently with a writer and lifts write throughput when several caches or processes share one file, which is the recommended mode for a database holding more than one provider's series. The setting is applied best-effort: a database that does not support WAL - notably an in-memory database - is left in its native journal mode rather than failing.

Disable it for storage where WAL is unsupported or undesirable, such as some network file systems.

Methods

TryValidate(out string?)

Attempts to validate the options without throwing, reporting the first invariant that is violated.

public override bool TryValidate(out string? error)

Parameters

error string

When this method returns false, a message describing the first violated invariant; otherwise null.

Returns

bool

true when every invariant holds; otherwise false.

Remarks

The dependency-injection registration wires this method into ValidateOnStart so misconfiguration fails fast at application startup. It mirrors the invariants of Validate() but returns a message rather than throwing with a ParamName. Storage-specific option types override this method to add their own invariants after invoking the base implementation.

Validate()

Validates the option values, throwing when a rule is violated.

public override void Validate()

Exceptions

ArgumentNullException

Thrown when Provider is null.

ArgumentException

Thrown when Provider is empty or white space, or when neither DatabaseFilePath nor ConnectionString is supplied.

ArgumentOutOfRangeException

Thrown when BusyTimeout is negative.

Applies to

ProductVersions
.NET8, 10