imgICache

Please add a summary to this article.
Inherits from: nsISupports Last changed in Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)

As of Firefox 18, there is no longer a single image cache. That means that using getService in order to obtain it will yield incorrect results. Use the following snippet to obtain a relevant image cache for a given document or channel (where relevantDocument is a Document object that contains images you care about, or relevantChannel is an nsIChannel that is used for fetching images):

var tools = Components.classes["@mozilla.org/image/tools;1"].getService(Components.interfaces.imgITools);
var cache = tools.getImgCacheForDocument(relevantDocument);
// alternatively, tools.getImgCacheForChannel(relevantChannel)

If there is no relevant document or channel, null may be passed, but this will cause any image cache requests to use the permanent storage cache (ie. any images from windows in private browsing mode will not be present in the cache returned from a call with a null parameter).

Method overview

void clearCache(in boolean chrome);
nsIProperties findEntryProperties(in nsIURI uri);
void removeEntry(in nsIURI uri);

Methods

clearCache()

Evict images from the cache.

void clearCache(
  in boolean chrome
);
Parameters
chrome
If true, evict only chrome images. If false, evict everything except chrome images.

Requires Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)

findEntryProperties()

Find Properties Used to get properties such as 'type' and 'content-disposition' 'type' is a nsISupportsCString containing the images' mime type such as 'image/png' 'content-disposition' will be a nsISupportsCString containing the header If you call this before any data has been loaded from a URI, it will succeed, but come back empty.

nsIProperties findEntryProperties(
  in nsIURI uri
);
Parameters
uri
The URI to look up.
Return value

null if the URL was not found in the cache.

removeEntry()

Evict images from the cache.

void removeEntry(
  in nsIURI uri
);
Parameters
uri
The URI to remove.
Exceptions thrown
NS_OK
If a uri was removed from the cache.
NS_ERROR_NOT_AVAILABLE
If a uri was unable to be removed from the cache.

Document Tags and Contributors

 Contributors to this page: Sheppy, jdm, trevorh
 Last updated by: Sheppy,