0

For an angular app, I was previously loading all data before displaying any page through the ui-router resolve. However, certain data was repeated, so I ended up caching the data via localStorage... but what would be the best way forward, in terms of combining the cache and promises to work together. Should I resolve a promise in the parent using the cache, and then simply use that promise throughout the app? Or should I resolve a promise separately using the cache in every single state? Or should I not even involve resolving promises for cacheable data, and simply call the cacheable data directly within each of the page controllers?

Any hints would be appreciated.

1 Answer 1

0

I'd say abstract your localStorage cache out of the controller level and put in your data service, that way you don't have to worry about where your data is coming from. And then just get that data with promises. Also, I'd recommend avoiding the pre-loading of data for child pages and just load it on demand.

Sign up to request clarification or add additional context in comments.

3 Comments

First of all thank for taking the time to answer. I think your answer is composed of two suggestions. Unfortunately, I don't understand either of them completely.
Regarding the first point, you said, "abstract your localStorage cache out of the controller level and put in your data service"... what does that mean? How do I abstract my localStorage cache out of the controller level? If you are talking about removing access to cache from the controllers... then how are the pages supposed to access the cache?
Regarding your second point, "avoiding the pre-loading of data for child pages and just load it on demand"... agian I am not quite sure what you mean. What is "on demand", and how is it implemented?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.