PdfImageCache class

A process-wide cache of decoded image XObjects, so repeat renders of a page reuse the already-decoded ui.Image instead of re-running the codec. The same image is decoded once and shared by every render path - the on-screen page, its thumbnail, the fast-scroll preview, the eyedropper sampler, and re-renders after a zoom/page-colour/annotation change - for the life of the document.

Lifetime mirrors the other ui.Image caches in this package (PdfPagePreviewCache, the thumbnail strip): the cache holds a master and hands out ui.Image.clones, so a caller disposing its copy (or eviction dropping the master) can never pull pixels out from under a recorded picture that is still painting.

Keys are image identity: an XObject keys by its CosStream (the xref cache returns the same instance across passes and renders of one document), an inline image by its content (PdfInlineImageKey). A new document revision opens fresh streams, so its images miss and re-decode; the dead entries age out under the byte budget. Decoded pixels vary enormously in size (a thumbnail icon vs. a full-page scan), so eviction is by total decoded bytes (maxBytes), oldest-touched first, not by a flat entry count.

Constructors

PdfImageCache({int? maxBytes, bool registerForPressure = false})
A cache holding at most maxBytes of decoded pixels, defaulting to the budget this platform can afford (pdfDefaultImageCacheBytes).

Properties

bytes int
Estimated bytes of decoded pixels held right now, against maxBytes.
no setter
debugHits int
Lookups served from cached pixels - for tests and the budget benchmark.
no setter
debugLength int
Number of cached masters - for tests.
no setter
debugMisses int
Lookups that had to decode - for tests and the budget benchmark.
no setter
hashCode int
The hash code for this object.
no setterinherited
maxBytes int
Eviction budget: the cache holds at most this many bytes of decoded pixels (estimated as width × height × 4), evicting the least-recently used master first. Lowering it trims to the new budget at once.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Empties the cache (a document close, a memory-pressure signal, test isolation). Outstanding clones the callers hold are unaffected.
debugResetCounters() → void
Zeroes the hit/miss counters (they survive clear, which is a cache operation, not a new measurement).
dispose() → void
evict(Object key) → void
Drops the cached master for key (e.g. an image whose stream changed).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(Object key, Image master) Image
Stores master under key (the cache takes ownership of it) and returns a clone for the caller to use and dispose. The master stays cached until evicted.
take(Object key) Image?
A clone of the cached image for key (the caller owns and disposes it), or null on a miss. Counts as a use for LRU ordering.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance PdfImageCache
The shared cache every render path consults by default.
final