I am using HttpContext.Cache to cache my data but it only works in my localhost.
In production, the cache doesn't works, my method always go to my database retrive the data, instead catch them from the cache. I use just one instance of Sql Server and one web server.
My code is like this
protected void LoadMenuSistem()
{
string menu = "";
if (Cache["menuSistem"] != null)
{
Response.Write(Cache["menuSistem"].ToString());
}
else
{
// Retrive data from database and开发者_StackOverflow社区 populate the string menu
}
Cache["menuSistem"] = menu;
}
please check the CPU Usage and RAM size in your production server. incase of low memory in the server cached items to be removed to free memory based on the priority set. This process is known as scavenging.
精彩评论