I have a web application where I would like to pull user settings from a database and store them for Global access. Would it make more sense to store the data in a Singleton, or a Session object? What’s the difference between the two?
Is it better to store the data as an object reference or break it up into value type objects (ints and strings)?
Session. That’s what it’s for. The session is stored in the global cache (basically a singleton), keyed by the session id. That way, you get only the data for the session of interest. Using a singleton would basically be replicating the global cache and you’d have to reinvent the mechanism to retrieve data for each session independently.
Go ahead and store the object. Let the Session worry about serializing it to something that can be restored. Be careful, though, with what you put in the Session. You don’t want to store too much data there or you’ll use up a lot of memory (assuming an in-memory cache).