Я хочу иметь возможность кэшировать http-вызов, но также принудительно обновлять кеш. Мой сервис выглядит так:
@Injectable()
export class UserService {
private currentUser$: Observable<User>;
constructor(private http: HttpClient) { }
getCurrentUser(force = false): Observable<User> {
if (!this.currentUser$ || force) {
this.currentUser$ = this.http.get<User>(`${environment.API_URL}/profiles/me`)
.pipe(
shareReplay(CACHE_SIZE)
);
}
return this.currentUser$;
}
}
Если я вызову getCurrentUser(true)
, переменная currentUser$
будет перезаписана. Боюсь, это сотрет всех существующих подписчиков. Это правда? Как мне их сохранить?