Home > Code > Caching > Accessing CACHE in class file

Accessing CACHE in class file

by Narain Siddharth   on May 01, 2011   Category: Caching   |  Views: 1116    |  Points: 25   |  Silver 


Below sample code shows, how to access the cache object in the class file

private string Country()
{
string strCountry = string.Empty;
if (System.Web.HttpContext.Current.Cache["MyCountry"] == null)
{
//Get the country details and assign into catch.
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;
}


Regards
Narain.


Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts