Table of Contents

InMemoryNotableDateCache Class

Definition

Namespace
Bodu.Globalization.Calendar.Caching
Assembly
Bodu.Globalization.Calendar.Caching.dll
Package
Bodu.Globalization.Calendar.Caching 1.0.0
Source
InMemoryNotableDateCache.cs

An INotableDateCache that stores computed years in memory for the lifetime of the instance, expiring them through the same freshness and version mechanism as the file caches.

public sealed class InMemoryNotableDateCache : NotableDateCacheBase<NotableDateCacheOptions>, INotableDateCache
Inheritance
InMemoryNotableDateCache
Implements
Inherited Members
Extension Methods

Remarks

Entries expire by time-to-live and resource version rather than by storage: the shared NotableDateCacheBase<TOptions> filters stale and superseded entries on read and prunes them on write. Nothing is persisted, so the cache starts empty on each process and is a drop-in alternative to the file caches when on-disk files are unwanted.

Reads and writes are individually thread-safe. As with every INotableDateCache, a concurrent store-after-store for the same territory resolves last-write-wins, which is acceptable for a best-effort cache.

Constructors

InMemoryNotableDateCache()

Initializes a new instance of the InMemoryNotableDateCache class with default options.

public InMemoryNotableDateCache()

InMemoryNotableDateCache(NotableDateCacheOptions)

Initializes a new instance of the InMemoryNotableDateCache class.

public InMemoryNotableDateCache(NotableDateCacheOptions options)

Parameters

options NotableDateCacheOptions

The cache options.

Exceptions

ArgumentNullException

Thrown when options is null.

Methods

Clear()

Removes every cached entry, returning the cache to its empty state.

public override void Clear()

Remarks

This is a best-effort operation: a backing-store failure is swallowed rather than thrown, consistent with the rest of the contract.

ReadEntries(string)

Reads the raw, unfiltered persisted entries for a normalized territory.

protected override IReadOnlyList<NotableDateCacheEntry> ReadEntries(string territory)

Parameters

territory string

The normalized territory key.

Returns

IReadOnlyList<NotableDateCacheEntry>

The stored entries, or an empty list when none are available or the read fails.

Remarks

Declared protected internal so the storage seam is open to the backends in this assembly and in the companion SQLite and distributed packages, which derive from this base. An unrelated third-party backend implements the public INotableDateCache contract directly instead, as NullNotableDateCache does.

WriteEntries(string, IReadOnlyList<NotableDateCacheEntry>)

Writes the supplied entries for a normalized territory, replacing any existing state.

protected override bool WriteEntries(string territory, IReadOnlyList<NotableDateCacheEntry> entries)

Parameters

territory string

The normalized territory key.

entries IReadOnlyList<NotableDateCacheEntry>

The entries to persist. The list is freshly allocated by the caller for this write, so a backend may store the reference directly without a defensive copy.

Returns

bool

true when the entries were persisted, including the deliberate deletion of an empty state; false when a storage failure was swallowed and nothing was persisted.

Remarks

Declared protected internal for the same reason as ReadEntries(string). The bool result lets StoreYear(NotableDateCacheEntry, TimeSpan, DateTimeOffset) distinguish a durable write from a best-effort backend that swallowed a fault, so a failed write is reported as Failed rather than falsely as Stored.

Applies to

ProductVersions
.NET8, 10