Closed krystalcode closed 8 years ago
I have tried adding a few seconds of delay before redirecting to the new state, but still the user is undefined in the cache. So I don't think it's a matter of redirecting before it's written in the cache, something else is going on. I'll investigate a bit more.
Apologies, my bad, something to do with Satellizer returning the data in different format than I was expecting and the user was not found and never really put into the cache.
I'm using the following piece of code when a user signs in on the application.
The home page requires the user object and in order to avoid an extra API request for an object that I already have, I'm taking the user from the cache in the HomeController.
However, even though I read that angular-cache is synchronous, it seems that the put operation is not. Angular directs to the new state, but the user is not available in the cache yet - the get operation returns 'undefined'. If I refresh the page, the user is available. That indicates that writing the object in the cache had not finished before the state change.
Why is that? Is there any way to make the put operation really synchronous? e.g. the code does not further execute until the object is put in the cache. Otherwise, would using a promise work, based on something like https://github.com/jmdobry/angular-cache/issues/123.