I would like to use Cache for my web application.
Here is the question
I found this link, http://msdn.microsoft.com/en-us/library/18c1wd61.aspx
For that link, all the example use something like Cache["KeyName"]="blah blah blah";
When I try to do the same thing, I have an error message, said "using System.Web.Caching.Cache is a type but used like a variable"
What should I do?
Do I have to create an instance?
My Example
string test = "123";
if (HttpContext.Cache["test"] != null)
test = (string)HttpContext.Cache["test"];
else
HttpContext.Cache["test"] = test;
I think you are getting some overlap of naming. Be explicit and see if it works:
You can also do the following in your ASP.NET codebehind:
or
Cacheis handled by ASP.NET so you just have to use it, not create it.EDIT: In ASP.NET MVC you can use the following in your controller: