Skip to content

Commit d7e8063

Browse files
committed
replace cache getter with evictFromCache method for CachedAssetReader
1 parent 28d96ab commit d7e8063

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/src/asset/cache.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,23 @@ class AssetCache {
4040
/// will first look up values in the [AssetCache], and if not present it will
4141
/// use the [AssetReader] and add the [Asset] to the [AssetCache].
4242
class CachedAssetReader extends AssetReader {
43-
final AssetCache cache;
43+
final AssetCache _cache;
4444
final AssetReader _reader;
4545
/// Cache of ongoing reads by [AssetId].
4646
final _pendingReads = <AssetId, Future<String>>{};
4747
/// Cache of ongoing hasInput checks by [AssetId].
4848
final _pendingHasInputChecks = <AssetId, Future<bool>>{};
4949

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+
}
5156

5257
@override
5358
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);
5560

5661
_pendingHasInputChecks.putIfAbsent(id, () async {
5762
var exists = await _reader.hasInput(id);
@@ -63,13 +68,13 @@ class CachedAssetReader extends AssetReader {
6368

6469
@override
6570
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);
6873
}
6974

7075
_pendingReads.putIfAbsent(id, () async {
7176
var content = await _reader.readAsString(id, encoding: encoding);
72-
cache.put(new Asset(id, content));
77+
_cache.put(new Asset(id, content));
7378
_pendingReads.remove(id);
7479
return content;
7580
});

lib/src/generate/build_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class BuildImpl {
148148
var node = _assetGraph.get(id);
149149
if (node == null) return;
150150
if (_reader is CachedAssetReader) {
151-
(_reader as CachedAssetReader).cache.remove(id);
151+
(_reader as CachedAssetReader).evictFromCache(id);
152152
}
153153

154154
/// Update all ouputs of this asset as well.

0 commit comments

Comments
 (0)