Home > Mobile >  How to not cache an http response with angular httpClient.subcribe()
How to not cache an http response with angular httpClient.subcribe()

Time:08-02

i am using ionic/angular for my app. In the starting screen (not splashscreen) I get a .json file from my server with

this.apiService.getEvents().subscribe res => {
                    console.log(res);
});


getEvents(): Observable<any> {
    let headers = new HttpHeaders({
      'Content-Type': 'application/json; charset=utf-8'
    });
    return this.httpClient.get("https:www.someURL.com/somejson.json", { headers: headers });
  }

but the Observable thingy is caching the whole response. Our file "somejson.json" is manually changed and the ionic app should reload its content at every appstart.

So, how do you NOT cache HTTP GET ? thanks in advance ;)

CodePudding user response:

Please use destroy before subscribing to avoid caching.

private readonly _destroy$: Subject<void> = new Subject<void>();
this.apiService.getEvents().pipe(takeUntil(this._destroy$)).subscribe res => {
                console.log(res);
});
  • Related