Cache Infrastructure

HotPDF provides bounded memory caching plus persistent caches for reusable font subsets and rendered pages

Weighted memory cache

THPDFWeightedCache in HPDFCache owns TObject values, indexes them by AnsiString, and evicts the least recently used values until their combined weight fits MaxBytes

Content keys

function HPDFCacheKeyOfBytes(const Bytes: TBytes): AnsiString;
function HPDFCacheKeyOfStream(Stream: TStream): AnsiString;

Both functions return the same lowercase SHA-256 hexadecimal key for the same content

HPDFCacheKeyOfStream hashes without allocating a second full-size byte array, reads seekable streams from position zero, and restores their original position

Persistent font-subset cache

Set THotPDF.FontSubsetCacheFolder to enable reusable TrueType and OpenType subset results while EnableFontSubsetting is active

PDF.EnableFontSubsetting := True;
PDF.FontSubsetCacheFolder := 'C:\ProgramData\MyApp\HotPDF\FontSubsets';
PDF.FontSubsetCacheMaxBytes := 256 * 1024 * 1024;

Persistent rendered-page cache

Set THotPDF.RenderCacheFolder to enable the disk tier used after the in-memory rendered-page cache

Ownership

Related APIs