Class DiskPortrayalInstructionCache
Disk-backed IPortrayalInstructionCache: persists each prepared S-100 Part 9 display list as a sidecar file so the cold first open of a previously-portrayed dataset — including after a process restart — skips the portrayal run (for S-101 the ~1 s MoonSharp Lua execution).
public sealed class DiskPortrayalInstructionCache : IPortrayalInstructionCache
- Inheritance
-
DiskPortrayalInstructionCache
- Implements
- Inherited Members
Remarks
The companion InMemoryPortrayalInstructionCache only helps re-opens within one session and is lost on restart; this implementation closes that gap by persisting the list to disk. The cache is correct only when the caller's key fully captures every portrayal input — see IPortrayalInstructionCache — which the S-101 processor ensures by folding the dataset content hash, the feature- and portrayal-catalogue content hashes, the engine/format stamp, and the mariner + ECDIS state into the key.
Robustness mirrors DiskPatternClipCache: any IO error, truncated /
corrupt file, or FormatVersion
mismatch is treated as a miss (the factory runs and overwrites); failures
never propagate. Writes are atomic (temp file + move). The cache is bounded
by a total-bytes cap with least-recently-used eviction (see
DiskCacheBudget), and the directory is shared across every
processor, so all members are thread-safe. Hits read and deserialize
without a lock, so concurrent loads do not serialize on the cache.
Constructors
DiskPortrayalInstructionCache(string, long)
Creates a disk-backed display-list cache rooted at
cacheDirectory.
public DiskPortrayalInstructionCache(string cacheDirectory, long maxBytes)
Parameters
cacheDirectorystringDirectory under which sidecar files are stored. Created on first write if absent. Assumed private to this cache (the LRU sweep enumerates every
*.dlistfile in it).maxByteslongSoft upper bound, in bytes, on the total size of all persisted files. After a write that exceeds it, the least-recently-used files are evicted until the total is at or below this cap. Must be positive.
Exceptions
- ArgumentException
cacheDirectoryis null or empty.- ArgumentOutOfRangeException
maxBytesis not positive.
Properties
Hits
Number of GetOrCompute(string, Func<IReadOnlyList<DrawingInstruction>>) calls served from the cache (the portrayal run was skipped). Exposed for diagnostics and tests.
public long Hits { get; }
Property Value
MaxBytes
Soft upper bound, in bytes, on the total size of the persisted entries.
public long MaxBytes { get; }
Property Value
Misses
Number of GetOrCompute(string, Func<IReadOnlyList<DrawingInstruction>>) calls that ran the factory (cache miss). Exposed for diagnostics and tests.
public long Misses { get; }
Property Value
TotalBytes
The total size, in bytes, of the persisted entries. The first call reads the cache directory if no write has done so yet.
public long TotalBytes { get; }
Property Value
Methods
Contains(string)
Whether an entry is persisted for key. Checks only
that the file exists: it neither reads nor validates the entry, and does
not mark it used.
public bool Contains(string key)
Parameters
keystringA key as passed to GetOrCompute(string, Func<IReadOnlyList<DrawingInstruction>>).
Returns
GetOrCompute(string, Func<IReadOnlyList<DrawingInstruction>>)
Returns the cached drawing-instruction list for key,
invoking factory to compute and store it on a miss.
public IReadOnlyList<DrawingInstruction> GetOrCompute(string key, Func<IReadOnlyList<DrawingInstruction>> factory)
Parameters
keystringAn opaque key that fully identifies the portrayal inputs (see the type remarks). The same key must always map to the same instruction list.
factoryFunc<IReadOnlyList<DrawingInstruction>>Runs the portrayal pipeline to produce the instruction list when the key is not cached. Only invoked on a miss.
Returns
- IReadOnlyList<DrawingInstruction>
The drawing-instruction list, in the same order as produced by the pipeline (the order is significant: it is the renderer's final priority tie-breaker). On a disk-cache hit the returned instances are freshly deserialized but value-equivalent to the originals.
GetOrComputeAsync(string, Func<CancellationToken, ValueTask<IReadOnlyList<DrawingInstruction>>>, CancellationToken)
Async counterpart to GetOrCompute(string, Func<IReadOnlyList<DrawingInstruction>>). Used by callers that
drive the portrayal pipeline asynchronously (the standard render path)
so the factory can await instead of blocking.
public ValueTask<IReadOnlyList<DrawingInstruction>> GetOrComputeAsync(string key, Func<CancellationToken, ValueTask<IReadOnlyList<DrawingInstruction>>> factory, CancellationToken cancellationToken = default)
Parameters
keystringfactoryFunc<CancellationToken, ValueTask<IReadOnlyList<DrawingInstruction>>>cancellationTokenCancellationToken