Вы имеете в виду в своей функции do (), где будут некоторые проблемы для параллельных запросов?Мол, 2 запроса делают с одним и тем же URL, тогда оба запроса будут отправлены на сервер и помещены в кэш.
Как насчет этого?Не для того, чтобы поместить HttpResponse в кеш, а чтобы поместить этот наблюдаемый объект.как это:
if (req.method == 'GET') {
// return cached object if exists
const cachedResponse = this.cache.get(req) || null;
if (cachedResponse) {
return cachedResponse); // it is Observable, even same req in the sam,e time, the second will get a Observable data.
}
// call api and cache result if doesn't exist
const result = next.handle(req);
this.cache.put(req, result)
result.do(event => {
if (event !instanceof HttpResponse) {
this.cache.remove(req) // if it is error, maybe remove?
}
return result;
});
}
return next.handle(req);