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;
}