I am using asp.net applicaion as shedular i am using chache to expire after 1 hours mean when cache expires it run perticular to activity
Problem: I have set for chache expire for 2 minutes it is working fine if i set it for 1 hour i am loosing the cache value before it get reassigned(hosted in server 2003 as web site)
Is there any IIS configuration is required to hold the cache for long time Or any change in code is required, please help me any one to solve this issue
Problem: I have set for chache expire for 2 minutes it is working fine if i set it for 1 hour i am loosing the cache value before it get reassigned(hosted in server 2003 as web site)
Is there any IIS configuration is required to hold the cache for long time Or any change in code is required, please help me any one to solve this issue
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Member
4 Points
42 Posts
Asp.net application as Shedular by using cache expire in global.asax
Aug 12, 2009 09:01 AM|chainv|LINK
I am using asp.net applicaion as shedular i am using chache to expire after 1 hours mean when cache expires it run perticular to activity
Problem: I have set for chache expire for 2 minutes it is working fine if i set it for 1 hour i am loosing the cache value before it get reassigned(hosted in server 2003 as web site)
Is there any IIS configuration is required to hold the cache for long time Or any change in code is required, please help me any one to solve this issue
below code for reference:
void Application_Start(object sender, EventArgs e)
{
RegisterCacheEntry();
}
private bool RegisterCacheEntry()
{
try
{
if (null != HttpContext.Current.Cache[DummyCacheItemKey]) return false;
HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", null,
DateTime.Now.AddHours(1), TimeSpan.FromHours(0),
CacheItemPriority.Normal,
new CacheItemRemovedCallback(CacheItemRemovedCallback));
FileWriting("RegisterCacheEntry:");
}
catch (Exception ex)
{
FileWriting("RegisterCacheEntry Error:");
}
return true;
}
public void CacheItemRemovedCallback(string key,
object value, CacheItemRemovedReason reason)
{
HitPage();
// Do the service works
DoWork();
}
private static string DummyPageUrl = ConfigurationManager.AppSettings["DummyURL"].ToString();
private void FileWriting( string str)
{
try
{
using (StreamWriter writer =
new StreamWriter(@"C:\Cachecallback.txt", true))
{
writer.WriteLine(str+"{0}", DateTime.Now);
writer.Close();
}
}
catch (Exception x)
{
throw(x);
}
}
private void HitPage()
{
try
{
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadData(DummyPageUrl);
FileWriting("HitPage");
}
catch (Exception ex)
{
using (StreamWriter writer =
new StreamWriter(@"C:\Cachecallback.txt", true))
{
writer.WriteLine("HitPage Exception: {0}", DateTime.Now.ToString() + "----" + ex.Message);
writer.Close();
}
}
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
try
{
if (HttpContext.Current.Request.Url.ToString().EndsWith("dummypage.aspx"))
{
FileWriting("Application_BeginRequestInside:");
RegisterCacheEntry();
}
}
catch (Exception ex)
{
FileWriting("Application_BeginRequest Error:");
}
}
Problem: I have set for chache expire for 2 minutes it is working fine if i set it for 1 hour i am loosing the cache value before it get reassigned(hosted in server 2003 as web site)
Is there any IIS configuration is required to hold the cache for long time Or any change in code is required, please help me any one to solve this issue
All-Star
54877 Points
5589 Posts
Re: Asp.net application as Shedular by using cache expire in global.asax
Aug 18, 2009 02:48 AM|Thomas Sun – MSFT|LINK
Hi,
The lifetime of the cache is equivalent to the lifetime of the application. In other words, when the application is restarted, the cache is recreated.
When we modify some files, such as Bin, web.config, etc, application will restart. For more information, see http://msdn.microsoft.com/en-us/library/ms178473.aspx
You also can configure to be recycled after a set elapsed time. For more information, see http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/1eee28e2-b319-4b4e-8267-a8c0aa0dcf36.mspx?mfr=true
I look forward to receiving your test results.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.