Table of Contents

IByteCache<TKey> Interface

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.dll
Package
Bodu.Financial.ExchangeRates 1.3.0
Source
IByteCache{T}.cs

Caches the raw bytes of a downloaded response so an identical download unit need not be re-fetched.

public interface IByteCache<TKey>

Type Parameters

TKey

The type identifying a cached download unit (a date range, feed, era, and so on).

Extension Methods

Remarks

A response is keyed by the download unit that produced it. Because a unit that covers the recent past can gain a new observation over time, a cached entry is treated as stale once it is older than a caller-supplied refresh interval. Implementations are expected to be resilient: a cache failure should manifest as a miss rather than an exception that breaks rate retrieval.

Methods

Store(TKey, byte[])

Stores the bytes for a download unit, replacing any existing entry.

void Store(TKey key, byte[] bytes)

Parameters

key TKey

The download unit the bytes belong to.

bytes byte[]

The response bytes to store.

TryGet(TKey, TimeSpan, out byte[])

Attempts to retrieve the cached bytes for a download unit.

bool TryGet(TKey key, TimeSpan refreshInterval, out byte[] bytes)

Parameters

key TKey

The download unit to look up.

refreshInterval TimeSpan

The maximum age at which a cached response is still considered fresh.

bytes byte[]

When this method returns true, the cached response bytes; otherwise null.

Returns

bool

true when a fresh cache entry exists; otherwise false.

TryGet(TKey, TimeSpan, out byte[], out DateTimeOffset?)

Attempts to retrieve the cached bytes for a download unit, together with the instant they were stored.

bool TryGet(TKey key, TimeSpan refreshInterval, out byte[] bytes, out DateTimeOffset? storedAtUtc)

Parameters

key TKey

The download unit to look up.

refreshInterval TimeSpan

The maximum age at which a cached response is still considered fresh.

bytes byte[]

When this method returns true, the cached response bytes; otherwise null.

storedAtUtc DateTimeOffset?

When this method returns true, the instant the entry was stored, or null when the cache does not record it; otherwise null.

Returns

bool

true when a fresh cache entry exists; otherwise false.

Remarks

A provider stamps a load served from the cache with storedAtUtc, the time its bytes were fetched from the source, rather than the time they were read back. The default implementation calls TryGet(TKey, TimeSpan, out byte[]) and reports no stored time, so a cache that does not record one keeps working unchanged.

Applies to

ProductVersions
.NET8, 10