<p>Let's say I have a list of categories for navigation on a web app.  Rather than selecting from the database for every user, should I add a function call in the application_onStart of the global.asax to fetch that data into an array or collection that is re-used over and over.  If my data does not change at all - (Edit - very often), would this be the best way?</p>

[{'answer_id': 64307, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': '<p>I use a static collection as a private with a public static property that either loads or gets it from the database.</p>\n\n<p>Additionally you can add a static datetime that gets set when it gets loaded and if you call for it, past a certain amount of time, clear the static collection and requery it.</p>\n'}, {'answer_id': 64319, 'author': 'Dana', 'author_id': 7856, 'author_profile': 'https://Stackoverflow.com/users/7856', 'pm_score': 1, 'selected': False, 'text': "<p>If it never changes, it probably doesn't need to be in the database.</p>\n\n<p>If there isn't much data, you might put it in the web.config, or as en Enum in your code.</p>\n"}, {'answer_id': 64339, 'author': 'Vadym Stetsiak', 'author_id': 6952, 'author_profile': 'https://Stackoverflow.com/users/6952', 'pm_score': 1, 'selected': False, 'text': '<p>Fetching all may be expensive. Try lazy init, fetch only request data and then store it in the cache variable.</p>\n'}, {'answer_id': 64359, 'author': 'Ryan Roper', 'author_id': 8273, 'author_profile': 'https://Stackoverflow.com/users/8273', 'pm_score': 2, 'selected': False, 'text': '<p>Premature optimization is evil. That being a given, if you are having performance problems in your application and you have "static" information that you want to display to your users you can definitely load that data once into an array and store it in the Application Object. You want to be careful and balance memory usage with optimization.</p>\n\n<p>The problem you run into then is changing the database stored info and not having it update the cached version. You would probably want to have some kind of last changed date in the database that you store in the state along with the cached data. That way you can query for the greatest changed time and compare it. If it\'s newer than your cached date then you dump it and reload.</p>\n'}, {'answer_id': 64361, 'author': 'Al.', 'author_id': 7921, 'author_profile': 'https://Stackoverflow.com/users/7921', 'pm_score': 1, 'selected': False, 'text': '<p>In an application variable.</p>\n\n<p>Remember that an application variable can contain an object in .Net, so you can instantiate the object in the global.asax and then use it directly in the code.</p>\n\n<p>Since application variables are in-memory they are very quick (vs having to call a database)</p>\n\n<p>For example:</p>\n\n<pre><code>// Create and load the profile object\nx_siteprofile thisprofile = new x_siteprofile(Server.MapPath(String.Concat(config.Path, "templates/")));\nApplication.Add("SiteProfileX", thisprofile);\n</code></pre>\n'}, {'answer_id': 64840, 'author': 'ADB', 'author_id': 3610, 'author_profile': 'https://Stackoverflow.com/users/3610', 'pm_score': 3, 'selected': True, 'text': '<p>You can store the list items in the Application object. You are right about the <code>application_onStart()</code>, simply call a method that will read your database and load the data to the Application object.</p>\n\n<p>In Global.asax</p>\n\n<pre><code>public class Global : System.Web.HttpApplication\n{\n    // The key to use in the rest of the web site to retrieve the list\n    public const string ListItemKey = "MyListItemKey";\n    // a class to hold your actual values. This can be use with databinding\n    public class NameValuePair\n    { \n        public string Name{get;set;} \n        public string Value{get;set;}\n        public NameValuePair(string Name, string Value)\n        {\n            this.Name = Name;\n            this.Value = Value;\n        }\n    }\n\n    protected void Application_Start(object sender, EventArgs e)\n    {\n        InitializeApplicationVariables();\n    }\n\n\n    protected void InitializeApplicationVariables()\n    {\n        List&lt;NameValuePair&gt; listItems = new List&lt;NameValuePair&gt;();\n        // replace the following code with your data access code and fill in the collection\n        listItems.Add( new NameValuePair("Item1", "1"));\n        listItems.Add( new NameValuePair("Item2", "2"));\n        listItems.Add( new NameValuePair("Item3", "3"));\n        // load it in the application object\n        Application[ListItemKey] = listItems;\n    }\n }\n</code></pre>\n\n<p>Now you can access your list in the rest of the project. For example, in default.aspx to load the values in a DropDownList:</p>\n\n<pre><code>&lt;asp:DropDownList runat="server" ID="ddList" DataTextField="Name" DataValueField="Value"&gt;&lt;/asp:DropDownList&gt;\n</code></pre>\n\n<p>And in the code-behind file:</p>\n\n<pre><code>protected override void OnPreInit(EventArgs e)\n{\n    ddList.DataSource = Application[Global.ListItemKey];\n    ddList.DataBind();\n    base.OnPreInit(e);\n}\n</code></pre>\n'}, {'answer_id': 64927, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I would store the data in the Application Cache (Cache object).  And I wouldn't preload it, I would load it the first time it is requested.  What is nice about the Cache is that ASP.NET will manage it including giving you options for expiring the cache entry after file changes, a time period, etc.  And since the items are kept in memory, the objects don't get serialized/deserialized so usage is very fast.</p>\n\n<p>Usage is straightforward.  There are Get and Add methods on the Cache object to retrieve and add items to the cache respectively.</p>\n"}, {'answer_id': 64957, 'author': 'Smallinov', 'author_id': 8897, 'author_profile': 'https://Stackoverflow.com/users/8897', 'pm_score': 0, 'selected': False, 'text': "<p>Caching is the way to go. And if your into design patterns, take a look at the singleton.</p>\n\n<p>Overall however I'm not sure I'd be worried about it until you notice performance degradation.</p>\n"}]
['https://Stackoverflow.com/questions/64284', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1115144/']