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
GetandTryGetpromote a hit to most recently used and update request statisticsPeekandContainsKeyinspect entries without changing recency or request statisticsPuttakes ownership, replaces an existing key in place, and safely accepts the same object again when only its weight changesRemovefrees an entry, whileExtracttransfers ownership to the caller- Reducing
MaxBytesevicts entries immediately, andTrimToBudgetexposes the same convergence operation explicitly Hits,Misses,HitRate,Evictions,Rejections, andReplacementsexpose cache behaviour, whileResetStatisticsstarts a new measurement interval- Slot capacity grows geometrically and live entries remain linked in constant-time recency order
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
- The key covers the original font bytes, exact used-glyph bitmap, compact or sparse mode, and cache schema version
- Both the normal GDI font-store path and the registered Unicode-font finalizer reuse the same cache
- Compact PDF/A entries preserve the old-to-new GID map and new glyph count needed by
CIDToGIDMap - Entries are validated before use, corrupt entries are removed, and replacement uses an atomic same-directory move
FontSubsetCacheMaxBytesapplies immediately and evicts the least recently accessed exact cache files without traversing unrelated foldersGetFontSubsetCacheInforeports hits, misses, writes, evictions, corruption, rejections, write failures, bytes, and filesClearFontSubsetCacheremoves only font-subset entries and abandoned temporary entries from the configured folder
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
- Page files are keyed by document content, zero-based page index, DPI, effective optional-content visibility, colour intent, and fallback policy
- Layer and colour-intent changes select reusable state variants instead of discarding every cached bitmap
- PNG and index updates are atomic, and abandoned temporary files are removed during recovery
- Page reads refresh page-level recency, while document count, page count, and byte limits evict least recently used data
- Reducing a configured limit converges immediately instead of waiting for a later write
- Corrupt PNG files, stale or duplicate index rows, missing folders, and unindexed cache folders are repaired automatically
- Invalid document keys and coordinates are rejected before filesystem access
Ownership
THPDFWeightedCacheowns values passed toPutunless a value is returned byExtractTHPDFDiskPageCache.Lookupreturns a newly allocated bitmap owned by the caller- Bitmap values passed to
THPDFDiskPageCache.Storeremain owned by the caller