ImageGateway is currently setup to cache all responses:
```
ImageGateway.prototype.getThumb = function ( title ) {
var cachedThumb = this._cache[title],
$window = util.getWindow(),
imageSizeMultiplier = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) ?
window.devicePixelRatio : 1;
if ( !cachedThumb ) {
this._cache[title] = this.api.get( actionParams( {
prop: 'imageinfo',
titles: title,
iiprop: [ 'url', 'extmetadata' ],
// request an image devicePixelRatio times bigger than the reported screen size
// for retina displays and zooming
iiurlwidth: findSizeBucket( $window.width() * imageSizeMultiplier ),
iiurlheight: findSizeBucket( $window.height() * imageSizeMultiplier )
} ) ).then( function ( resp ) {
// imageinfo is undefined for missing pages.
if ( resp.query && resp.query.pages &&
resp.query.pages[0] && resp.query.pages[0].imageinfo ) {
return resp.query.pages[0].imageinfo[0];
}
throw new Error( 'The API failed to return any pages matching the titles.' );
} );
}
return this._cache[title];
};
```
However, the cache from ImageGateway is not being used and hasn't been used in a long time. On each `onSlide` event, ImageCarousel [[ https://github.com/wikimedia/mediawiki-extensions-MobileFrontend/blob/ed393746f6ae602666438517db37ed878108c22c/src/mobile.mediaViewer/ImageCarousel.js#L109 | makes a new instance of itself ]] and [[ https://github.com/wikimedia/mediawiki-extensions-MobileFrontend/blob/ed393746f6ae602666438517db37ed878108c22c/src/mobile.mediaViewer/ImageCarousel.js#L35 | makes a new instance of ImageGateway ]] which bypasses any benefits of the caching code.
This ticket is about utilizing this cache and making it production ready. In its current state, the code will cache all responses including failed responses! We should only cache successful responses though.
A possible way to utilize the cache is to make skins.minerva.scripts/init.js responsible for injecting an instance of ImageGateaway when it [[ https://github.com/wikimedia/mediawiki-skins-MinervaNeue/blob/8e352f7824d8e0a1bf8f4de0d33a68ad0eeccdf0/resources/skins.minerva.scripts/init.js#L97 | instantiates the mediaviewer overlay ]].
== Acceptance criteria
[] The cache logic in ImageGateway is being utilized by ImageCarousel.
[] ImageGateway only caches successful responses (not unsuccessful ones).