From 4c0f77e806417f2c399d48369401899c00476e22 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 1 Apr 2018 21:50:38 -0400 Subject: [PATCH] Use write lock --- lib/src/cache.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); } }