I am doing the Pluralsight course of Ionic (changes here and there, but so far so good) and I ran into an issue and well, it was the cache. I dug a little bit on it and I am asking for good practices. Let me simplify the idea (different topic than the course):
List of car brands (at /brands
), when I click on one brand, in my api service I set the brand and I navigate to /brand
.
In /brand
it calls the service, service knows the selected brand and request all its cars. So I can see a list of cars of that brand. Then I click one car and I go to /car/:id
and I see some details.
I go back to the home page (/brands
) and I click a different brand, I notify the api service to change its brand and I navigate to /brand
and it shows the old brand cars. In other words, what you see in /brand
depend on a variable of the api service (AKA the first queried brand)
So what I saw here is that states are cached per parameter, so /brand
is always cached and also I have a cached /car/1
and a cached /car/2
.
So the issue here is since /brand
is cached, every time I hit that state, no matter if I changed the brand internally, it is going to load the wrong data.
I can simply disable cache for that view, but in the case of this app, there are at least 4-5 states like that so I need to find a better way.
Maybe the whole idea of having the brand saved on the api is a bad idea and I should have stuff like /brand/1
and /brand/2
so I never hit a state with the wrong data.
If that is the good idea, I have another question. Is an abstract state (a side menu) also cached? I can use that as well to load my states using params, but if that is going to be cached, I can’t change the params there. Maybe I can disable the cache for side menu.
Thoughts?