diff --git a/lib/src/cache.dart b/lib/src/cache.dart index d1d16f16..75bb8c51 100644 --- a/lib/src/cache.dart +++ b/lib/src/cache.dart @@ -109,8 +109,12 @@ class ResponseCache { } // Save the response. - _cache[req.uri.path] = new _CachedResponse( - new Map.from(res.headers), res.buffer.toBytes(), now); + var writeLock = _writeLocks.putIfAbsent(req.uri.path, () => new Pool(1)); + await writeLock.withResource(() { + _cache[req.uri.path] = new _CachedResponse( + new Map.from(res.headers), res.buffer.toBytes(), now); + }); + _setCachedHeaders(now, req, res); } }