8.7 released—WinterCG Compliance Part 1
Learn more
ImageCache
Represents a class that stores handles image download requests and caches the already downloaded images.

Summary

Constructors

constructor

new ImageCache(): ImageCache
inherited from constructor
Returns ImageCache

Properties

maxRequests

maxRequests: number
The maximum number of simultaneous download requests. Defaults to 5.

placeholder

placeholder: ImageSource
The image to be used to notify for a pending download request - e.g. loading indicator.

downloadErrorEvent

Static
downloadErrorEvent: string
String value used when hooking to download error event.

downloadedEvent

Static
downloadedEvent: string
String value used when hooking to downloaded event.

Methods

clear

clear(): void
Removes all the previously cached images.
Returns void

disableDownload

disableDownload(): void
Temporary disables download requests.
Returns void

enableDownload

enableDownload(): void
Enables previously suspended download requests.
Returns void

enqueue

enqueue(request: DownloadRequest): any
Adds a new download request at the end of the download queue. This will be the last download to start.
Parameter Default Description
request

Returns any

get

get(key: string): any
Gets the image for the specified key. May be undefined if the key is not present in the cache.
Parameter Default Description
key
string

Returns any

on

on(eventNames: string, callback: (args: EventData) => void, thisArg?: any): void
A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
Parameter Default Description
eventNames
string

String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").

callback
(args: EventData) => void

Callback function which will be executed when event is raised.

thisArg
any

An optional parameter which will be used as `this` context for callback execution.

Returns void
on(event: "downloaded", callback: (args: DownloadedData) => void, thisArg?: any): void
Raised when the image has been downloaded.
Parameter Default Description
event
"downloaded"

callback
(args: DownloadedData) => void

thisArg
any

Returns void
on(event: "downloadError", callback: (args: DownloadError) => void, thisArg?: any): void
Raised if the image download errors.
Parameter Default Description
event
"downloadError"

callback
(args: DownloadError) => void

thisArg
any

Returns void

push

push(request: DownloadRequest): any
Adds a new download request at the top of the download queue. This will be the next immediate download to start.
Parameter Default Description
request

Returns any

remove

remove(key: string): void
Removes the cache for the specified key.
Parameter Default Description
key
string

Returns void

set

set(key: string, image: any): void
Sets the image for the specified key.
Parameter Default Description
key
string

image
any

Returns void
Previous
ImageAsset