Angular 8 - Кэширование HTTP-запроса с использованием PublishReplay - PullRequest
0 голосов
/ 26 апреля 2020

Теперь я могу кешировать от 1 до 2 запросов HTTP одновременно в одном и том же компоненте и повторять его после истечения срока действия кэша, но когда я пытаюсь добавить еще 1 publishReplay () в сервис, когда я перехожу к другому компоненту и обратно , он останавливается на несколько секунд, прежде чем он возвращается.

getAllUsers(): Observable<any> {
if (this.reuse) {
  return this.reuse;
} else {
  return this.reuse = this.http.get(`${environment.url.userProfile}account-info`, this.userprofileKey()).pipe(
    publishReplay(1, 20000),
    refCount(),
    take(1)
  );
}

}

enter getUserInterests(): Observable<any> {
if (this.reuse3) {
  return this.reuse3;
} else {
  return this.reuse3 = this.http.get(`${environment.url.userProfile}interest`, this.userprofileKey()).pipe(
    publishReplay(1, 20000),
    refCount(),
    take(1)
  );
}

}

getEntitlementPlan(): Observable<any> {
if (this.reuse2) {
  return this.reuse2;
} else {
  return this.reuse2 = this.http.get(`${environment.url.entitlement}bau/subscription/current`, this.paymentKey()).pipe(
    publishReplay(1, 20000),
    refCount(),
    take(1)
  );
}

}

, если я удалю 1 publishReplay () от любого сверху. Работает плавно.

...