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:
HttpContext.Current.Cache["KeyName"]="blah blah blah";
You can also do the following in your ASP.NET codebehind:
Page.Cache["KeyName"]="blah blah blah";
or
this.Cache["KeyName"]="blah blah blah";
Cache is 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:
HttpContext.Cache["KeyName"]="blah blah blah";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With