Reputation: 306
I have a bunch of user preferences that they can set via a view. These preferences, once set, are available via an API either individually by key or as a whole. I am contemplating how to make these preferences available to my app in a way that won't cause me to hit the API every time I need one.
I should say that a number of the preferences are user defined HTML templates and are, therefore, quite large.
It seems that storing the preferences in a service is the obvious way forward, but taking this as a given, I seemingly have a couple of ways forward, but am sure there must be others...
Grab all the preferences when the app is first initiated and store them in the service. Any controller that needs them can inject the service. Reluctant to do this due to the size, as mentioned above.
Cache preferences in the service as they are grabbed when needed. So the API will be hit once for each preference. This seems like a possible way forward.
Something I've not thought of.
How do other people do this? Any advice or suggestions?
Upvotes: 1
Views: 176
Reputation: 5983
I would grab the settings from the server when the app starts up and store them in session storage. Wouldn't be hard to roll your own or we have used ngStorage
for similar things. https://github.com/gsklee/ngStorage
Upvotes: 1