Suppose each user has certain preferences that is saved in database for that user. For example: UnitSystem, UILanguage, TimeZone,…
When an http-request is made we need to have access to user preferences (e.g UnitSystem, TimeZone, …) to correctly process the data and render the view in the correct language.
What is the correct way to save/access user preferences during program execution?
- Read the user preferences from database for each http-request
- Read user preferences once when user logs into the application and save it in session variables.
- Read user preferences once when user logs into the application and save it in a cookie.
How do you handle global settings in your MVC based applications?
In your case, I would probably store the setting in the session and cookie and check them in this order:
That way you should be able to handle session timeouts & users with cookies turned off pretty transparently while still maximizing performance by hitting the DB only when absolutely necessary.
Of course you’ll need some mechanism to update the cookie and session as well if the user changes their preferences in the DB. Assuming these preferences are set in the same application, that shouldn’t be too big of a deal.