![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What am I doing wrong here? I am trying to Cache data for 5 minutes (absolute time). To test caching, I am writing to a log file every time the application determines that the Cache item is null and needs to pull the data from the database again. I run my asp.net form, then I hit refresh over and over. It logs that it is hitting the database for data because the cache is null. The cache should contain my data for 5 minutes - therefore, it should not call to the database. Here is my code (without the logging): string cacheKey = "CachedDomainDataSet"; object cacheObject = Cache[cacheKey] as DataSet; if(cacheObject == null) { cacheObject = DMSProcessing.FillDomainDataSet();//CALL DATABASE if(cacheObject != null) { //I've tried everything I can think of here. My last attempt has been to CacheItemPriority to NotRemovable. Cache.Insert(cacheKey, cacheObject, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null); } |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Hi Robin, Is it possible that DMSProcessing.FillDomainDataSet() is not returning a DataSet? From your code, you declared cacheObject as object, and you used "as DataSet" to read the cache. If it's not a DataSet, the cacheObject will always be null. Sincerely, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. If you are using Outlook Express, please make sure you clear the check box "Tools/Options/Read: Get 300 headers at a time" to see your reply promptly. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Hi Robin, Have you tried to read the cached object immdiately after you put it into the cache? Is it there? Another thing to check is receive the cache removing callback notification and check the CacheItemRemovedReason: protected void Page_Load(object sender, EventArgs e) { string cacheKey = "CachedDomainDataSet"; object cacheObject = Cache[cacheKey] as DataSet; if (cacheObject == null) { Response.Write("Creating new cache"); cacheObject = new DataSet(); if (cacheObject != null) { Cache.Insert(cacheKey, cacheObject, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, cache_Removed); } } } private void cache_Removed(string key, Object value, CacheItemRemovedReason reason) { } For the caching related config, you can find it here: #cache Element for caching (ASP.NET Settings Schema) http://msdn2.microsoft.com/en-us/library/ms228248.aspx You may check if your existing configuration has related information to this. Here's also some articles you may find useful: #John's Adventures: Why Does My ASP.NET Cache Keep Clearing Itself? http://www.johnsadventures.com/archi...pnet_cache_kee p_clearing_i.html Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Hi Robin, This <cache> element are new for .NET 2.0. Regarding the removed reason 'Removed': ======== (from CacheItemRemovedReason enumeration documentation) Removed The item is removed from the cache by a Remove method call or by an Insert method call that specified the same key. ======== This is expected since you're repeatedly inserting the same name cache object, which causes the previous one get removed. The root cause here is still that following code returns null on your server: object cacheObject = Cache[cacheKey] as DataSet; Since the CacheItemRemovedReason is 'Removed', which means it's actually there, with all due respect, I really cannot think of another reason other than "Cache[cacheKey] as DataSet" is null. Would you please help me double check that by declaring "cacheObject" as DataSet instead of Object? If this is not the case, I'm afraid you will have to contact Microsoft Customer Support and Service for live debugging or dump analysis to troubleshoot such issue. Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#9
| |||
| |||
|
#10
| |||
| |||
|
|
Hi Robin, Please help me test following simple code on your server: private void Page_Load(object sender, System.EventArgs e) { string cached = Cache["test"] as string; if (cached == null) { Response.Write("Not cached, inserting..."); Cache.Insert("test", DateTime.Now.ToString(), null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null); } else { Response.Write("Cached: " + cached); } } Try to visit the page and refresh for several times, and tell me the result. Thanks. Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |