I would like to cache some of the data, which is requested from the server. I modified the http request like this:
// user.ts
export class User {
id: number;
name: string;
}
// inside the component:
getUsers() : Observable<User[]> {
return this.http.get<User[]>(this.api+'/get-users').pipe(
tap(users => {
localStorage.setItem("cache_users", JSON.stringify(users));
})
);
}
How is it possible to load the users from the cache, if the request failed, because the server was unreachable?