Commit 52a7479d authored by Adam Barth's avatar Adam Barth

Limit the size of the image cache

Fixed #1009
parent dfcc0c71
......@@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:ui' as ui;
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:quiver/collection.dart';
import 'fetch.dart';
import 'image_decoder.dart';
......@@ -35,11 +36,16 @@ class _UrlFetcher implements ImageProvider {
int get hashCode => _url.hashCode;
}
const int _kDefaultSize = 1000;
class _ImageCache {
_ImageCache._();
final Map<ImageProvider, ImageResource> _cache =
new Map<ImageProvider, ImageResource>();
final LruMap<ImageProvider, ImageResource> _cache =
new LruMap<ImageProvider, ImageResource>(maximumSize: _kDefaultSize);
int get maximumSize => _cache.maximumSize;
void set maximumSize(int value) { _cache.maximumSize = value; }
ImageResource loadProvider(ImageProvider provider) {
return _cache.putIfAbsent(provider, () {
......
......@@ -11,6 +11,7 @@ dependencies:
sky_engine: 0.0.75
sky_services: 0.0.75
vector_math: '>=1.4.3 <2.0.0'
quiver: '>=0.21.4 <0.22.0'
# See the comment in flutter_tools' pubspec.yaml. We have to pin it
# here also because sky_services depends on mojo_sdk which depends
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment