As per title. I want to be able to save some data in a cache object but this object must be available to all users/sessions and can expire.
What is the best method to achieve this in a asp.net web app?
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.
HttpContext.Currentis available to all pages, but not necessarily to all threads. If you try to use it inside a background thread,ThreadPooldelegate, async call (using an ASP.NET Async page), etc., you’ll end up with aNullReferenceException.If you need to get access to the cache from library classes, i.e. classes that don’t have knowledge of the current request, you should use
HttpRuntime.Cacheinstead. This is more reliable because it doesn’t depend on anHttpContext.