Class DiskDatasetMetadataCache
Disk-backed IDatasetMetadataCache: persists each dataset's DatasetMetadata as a small sidecar file so a later session can recover it without re-parsing the dataset (issue #467 WS3).
public sealed class DiskDatasetMetadataCache : IDatasetMetadataCache
- Inheritance
-
DiskDatasetMetadataCache
- Implements
- Inherited Members
Remarks
Each sidecar stores the source file's last-write time and length
alongside the serialized metadata; a read is a hit only when both still
match the current file, so editing or replacing the dataset silently
invalidates the entry. Robustness mirrors
DiskPortrayalInstructionCache: any IO error, truncated / corrupt
file, envelope-version mismatch, or
FormatVersion mismatch is
treated as a miss; failures never propagate. Writes are atomic
(temp file + move), the store is bounded by a total-bytes cap with
least-recently-used eviction (see DiskCacheBudget), and all
members are thread-safe; hits are served without a lock.
Constructors
DiskDatasetMetadataCache(string, long)
Creates a disk-backed metadata cache rooted at
cacheDirectory.
public DiskDatasetMetadataCache(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
*.dmetafile 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 reads served from a valid cached entry.
public long Hits { get; }
Property Value
Misses
Number of lookups (via either GetOrRead(string, Func<string, DatasetMetadata>) or TryGet(string, out DatasetMetadata)) not served from a valid cached entry. In GetOrRead(string, Func<string, DatasetMetadata>) such a miss is where the producer runs; in TryGet(string, out DatasetMetadata) it simply returns false.
public long Misses { get; }
Property Value
Methods
GetOrRead(string, Func<string, DatasetMetadata>)
Returns the cached metadata for sourcePath when a
valid entry exists (source unchanged since it was written), otherwise
invokes producer, persists its result, and returns
it. A cache failure never propagates: the freshly produced value is
still returned.
public DatasetMetadata GetOrRead(string sourcePath, Func<string, DatasetMetadata> producer)
Parameters
sourcePathstringAbsolute path to the dataset file whose metadata is cached. Its last-write time and length form the validity key.
producerFunc<string, DatasetMetadata>Cold path invoked on a miss to parse the metadata from
sourcePath. Receives the same path.
Returns
- DatasetMetadata
The cached or freshly produced metadata.
TryGet(string, out DatasetMetadata)
Attempts to read a valid cached entry for sourcePath
without producing on a miss. Useful for a pure "is it already known?"
probe.
public bool TryGet(string sourcePath, out DatasetMetadata metadata)
Parameters
sourcePathstringAbsolute path to the dataset file.
metadataDatasetMetadataThe cached metadata when the method returns true.