Stopped increasing the cache size to accomodate large images. (#47387)
This commit is contained in:
parent
7a13d8a0ce
commit
31f399f973
@ -207,20 +207,16 @@ class ImageCache {
|
|||||||
// Images that fail to load don't contribute to cache size.
|
// Images that fail to load don't contribute to cache size.
|
||||||
final int imageSize = info?.image == null ? 0 : info.image.height * info.image.width * 4;
|
final int imageSize = info?.image == null ? 0 : info.image.height * info.image.width * 4;
|
||||||
final _CachedImage image = _CachedImage(result, imageSize);
|
final _CachedImage image = _CachedImage(result, imageSize);
|
||||||
// If the image is bigger than the maximum cache size, and the cache size
|
|
||||||
// is not zero, then increase the cache size to the size of the image plus
|
|
||||||
// some change.
|
|
||||||
if (maximumSizeBytes > 0 && imageSize > maximumSizeBytes) {
|
|
||||||
_maximumSizeBytes = imageSize + 1000;
|
|
||||||
}
|
|
||||||
_currentSizeBytes += imageSize;
|
|
||||||
final _PendingImage pendingImage = _pendingImages.remove(key);
|
final _PendingImage pendingImage = _pendingImages.remove(key);
|
||||||
if (pendingImage != null) {
|
if (pendingImage != null) {
|
||||||
pendingImage.removeListener();
|
pendingImage.removeListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
_cache[key] = image;
|
if (imageSize <= maximumSizeBytes) {
|
||||||
_checkCacheSize();
|
_currentSizeBytes += imageSize;
|
||||||
|
_cache[key] = image;
|
||||||
|
_checkCacheSize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (maximumSize > 0 && maximumSizeBytes > 0) {
|
if (maximumSize > 0 && maximumSizeBytes > 0) {
|
||||||
final ImageStreamListener streamListener = ImageStreamListener(listener);
|
final ImageStreamListener streamListener = ImageStreamListener(listener);
|
||||||
|
@ -121,14 +121,14 @@ void main() {
|
|||||||
expect(imageCache.currentSizeBytes, 256);
|
expect(imageCache.currentSizeBytes, 256);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Increases cache size if an image is loaded that is larger then the maximum size', () async {
|
test('Do not cache large images', () async {
|
||||||
const TestImage testImage = TestImage(width: 8, height: 8);
|
const TestImage testImage = TestImage(width: 8, height: 8);
|
||||||
|
|
||||||
imageCache.maximumSizeBytes = 1;
|
imageCache.maximumSizeBytes = 1;
|
||||||
await extractOneFrame(const TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty));
|
await extractOneFrame(const TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty));
|
||||||
expect(imageCache.currentSize, 1);
|
expect(imageCache.currentSize, 0);
|
||||||
expect(imageCache.currentSizeBytes, 256);
|
expect(imageCache.currentSizeBytes, 0);
|
||||||
expect(imageCache.maximumSizeBytes, 256 + 1000);
|
expect(imageCache.maximumSizeBytes, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Returns null if an error is caught resolving an image', () {
|
test('Returns null if an error is caught resolving an image', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user