I understand having a static variable in ASP.NET MVC does not warrant the variable is created only once.
What is the correct way to store a handful of frequently used objects (globally shared between requests) for the lifetime of the application?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would use regular ASP.NET data cache.
Application State is only useful if the data rarely changes, but by the sounds of the question, it will change often. It’s also free-threaded, and doesn’t scale (e.g in a web farm scenario).
With cache, you can control the expiry of the items, specify callbacks when the items are removed, use sliding expiration, access it via interfaces which means it can be tested easily (whereas application state will have to be mocked), and can scale easily if you set it up correctly.
It’s much more robust that a simple get/set wrapper around the application state.