@@ -40,18 +40,23 @@ class AssetCache {
40
40
/// will first look up values in the [AssetCache] , and if not present it will
41
41
/// use the [AssetReader] and add the [Asset] to the [AssetCache] .
42
42
class CachedAssetReader extends AssetReader {
43
- final AssetCache cache ;
43
+ final AssetCache _cache ;
44
44
final AssetReader _reader;
45
45
/// Cache of ongoing reads by [AssetId] .
46
46
final _pendingReads = < AssetId , Future <String >> {};
47
47
/// Cache of ongoing hasInput checks by [AssetId] .
48
48
final _pendingHasInputChecks = < AssetId , Future <bool >> {};
49
49
50
- CachedAssetReader (this .cache, this ._reader);
50
+ CachedAssetReader (this ._cache, this ._reader);
51
+
52
+ /// Evicts [id] from the underlying cache.
53
+ void evictFromCache (AssetId id) {
54
+ _cache.remove (id);
55
+ }
51
56
52
57
@override
53
58
Future <bool > hasInput (AssetId id) {
54
- if (cache .contains (id)) return new Future .value (true );
59
+ if (_cache .contains (id)) return new Future .value (true );
55
60
56
61
_pendingHasInputChecks.putIfAbsent (id, () async {
57
62
var exists = await _reader.hasInput (id);
@@ -63,13 +68,13 @@ class CachedAssetReader extends AssetReader {
63
68
64
69
@override
65
70
Future <String > readAsString (AssetId id, {Encoding encoding: UTF8 }) {
66
- if (cache .contains (id)) {
67
- return new Future .value (cache .get (id).stringContents);
71
+ if (_cache .contains (id)) {
72
+ return new Future .value (_cache .get (id).stringContents);
68
73
}
69
74
70
75
_pendingReads.putIfAbsent (id, () async {
71
76
var content = await _reader.readAsString (id, encoding: encoding);
72
- cache .put (new Asset (id, content));
77
+ _cache .put (new Asset (id, content));
73
78
_pendingReads.remove (id);
74
79
return content;
75
80
});
0 commit comments