I have a code for storing/caching each(or almost each) request in the object, but not sure is it good practice or not.
store = [];
fetchAll(params: any, cache = true): Observable<PostsInt[]> {
let posts = this.http.get<PostsInt[]>(this.getApiUrl('/posts'), {
params
});
if (cache) {
const key =
Object.values(params).join('') + APP_CONFIG.data.defaultLocale;
if (!this.store[key]) {
posts = posts.pipe(
publishReplay(1),
refCount()
);
this.store[key] = posts;
}
return this.store[key];
}
return posts;
}