Class InMemoryPortrayalInstructionCache
In-memory IPortrayalInstructionCache with a bounded least-recently-used eviction policy. A single instance shared across every processor lets the cold open of a previously-portrayed dataset — e.g. reopening a cell, or reloading an exchange set within the same session — reuse the prepared display list and skip the portrayal run.
public sealed class InMemoryPortrayalInstructionCache : IPortrayalInstructionCache
- Inheritance
-
InMemoryPortrayalInstructionCache
- Implements
- Inherited Members
Remarks
Unlike the disk cache this does not survive process restart and stores the list instances directly (no serialization), so a hit returns the exact same objects. All members are thread-safe (guarded by a single lock).
Constructors
InMemoryPortrayalInstructionCache(int)
Creates an in-memory cache holding at most capacity
distinct prepared display lists; the least-recently-used entry is evicted
when the capacity is exceeded.
public InMemoryPortrayalInstructionCache(int capacity = 64)
Parameters
capacityintMaximum number of cached lists. Must be positive.
Exceptions
- ArgumentOutOfRangeException
capacityis 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
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
Methods
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