Accessing CACHE in class file.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 309
First we have to give reference system.web in our project and in the class file give system.web as namespace.Then only we can access cache using HttpContext.Current
private string Country()
{
string strCountry = string.Empty;
if (System.Web.HttpContext.Current.Cache["MyCountry"] == null)
{
//Get the country details and assign into cache.
System.Web.HttpContext.Current.Cache["MyCountry"] = "test";
strCountry = System.Web.HttpContext.Current.Cache["MyCountry"].ToString();
}
else
{
strCountry = System.Web.HttpContext.Current.Cache["MyCountry"].ToString();
}
return strCountry;
}

Comments or Responses

Login to post response