ImageCache class

Class for caching images.

Implements a least-recently-used cache of up to 1000 images, and up to 100 MB. The maximum size can be adjusted using maximumSize and maximumSizeBytes. Images that are actively in use (i.e. to which the application is holding references, either via ImageStream objects, ImageStreamCompleter objects, ImageInfo objects, or raw dart:ui.Image objects) may get evicted from the cache (and thus need to be refetched from the network if they are referenced in the putIfAbsent method), but the raw bits are kept in memory for as long as the application is using them.

The putIfAbsent method is the main entry-point to the cache API. It returns the previously cached ImageStreamCompleter for the given key, if available; if not, it calls the given callback to obtain it first. In either case, the key is moved to the "most recently used" position.

Generally this class is not used directly. The ImageProvider class and its subclasses automatically handle the caching of images.

A shared instance of this cache is retained by PaintingBinding and can be obtained via the imageCache top-level property in the painting library.




currentSize int
The current number of cached entries.
currentSizeBytes int
The current size of cached entries in bytes.
maximumSize int
Maximum number of entries to store in the cache. [...]
read / write
maximumSizeBytes int
Maximum size of entries to store in the cache in bytes. [...]
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


clear() → void
Evicts all entries from the cache. [...]
evict(Object key) bool
Evicts a single entry from the cache, returning true if successful. Pending images waiting for completion are removed as well, returning true if successful. [...]
putIfAbsent(Object key, ImageStreamCompleter loader(), { ImageErrorListener onError }) ImageStreamCompleter
Returns the previously cached ImageStream for the given key, if available; if not, calls the given callback to obtain it first. In either case, the key is moved to the "most recently used" position. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
Returns a string representation of this object.


operator ==(dynamic other) bool
The equality operator. [...]