Cache response is not returned in resolve #38
Replies: 5 comments
-
Create a reproduction in stackblitz, please. |
Beta Was this translation helpful? Give feedback.
-
Stackblitz: https://stackblitz.com/edit/angular-ivy-bajvyj?file=src/app/league/league.service.ts If you set cache$ to true it's not working, if you set it to false it's working. |
Beta Was this translation helpful? Give feedback.
-
The issue is only with useHttpCacheLocalStorage? |
Beta Was this translation helpful? Give feedback.
-
No the issue is also when using in memory cache. I also tried to remove the guard, it's working. Same thing with only the resolve. So it seems that it's the combination of guard and resolve with both using a cached HTTP request. |
Beta Was this translation helpful? Give feedback.
-
If that can help, I encountered a very similar issue. The only difference is that there is no resolver in my case, just a guard and a component making the same cached call trough a dedicated service. That component is part of a Route config too. The quick fix I currently have is to add a @Injectable()
export class MyService {
// ...
fetchCats() {
return this.getSomeUrlFromAConfigFile().pipe(
delay(0),
switchMap(url => this.http.post<Cat[]>(url, {}, withCache()))
);
}
} To be noted that we use a custom |
Beta Was this translation helpful? Give feedback.
-
I'm submitting a...
Minimal reproduction of the problem with instructions
I have a route with a guard and a resolve. The same service is called in both and the called method is a HTTP request with caching enabled (useHttpCacheLocalStorage).
The service
The resolve (the tap operator is just to understand why it's not working)
The behavior is wrong when cache is empty
Cache is empty
Call getLeagues from guard => cache is populated
Call getLeagues from resolve => the tap operator is not called
Refresh the app (cache is already populated)
Call getLeagues from guard
Call getLeagues from resolve => the tap operator is called
Environment
Beta Was this translation helpful? Give feedback.
All reactions