Caching in Asp.net
I have observed a situation in my application where my Cache doesn't get expired when a user is still acessing my application. Let me explain in detail. I have set the Cache to expire after 10 second and I have mentioned NoAbsoluteExpiration. The code is something like this:
Cache.Insert("Data", value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10));
Now lets say after the first user has visite开发者_Python百科d the page, in the 9th second another user visits the application. In this case the Cache doens't get expired at the 10th second and extends itself to the next 10 seconds. This is an issue for our application because if every second I have a user visiting my site, the Cache will never expire. I found that the Cache expires only if the application is idle for 10 seconds. That is, if there is no hit to the site for 10 seconds.
How can I make it possible to get the Cache expired every 10 seconds, whether any user is still acessing the page or if the applicaion is idle.
Thanks in advance.
Well then use NoSlidingExpiration instead of NoAbsoluteExpiration and give it a timespan for absolute expiration.
Cache.Insert("Data", value, null, TimeSpan.FromSeconds(10), System.Web.Caching.Cache.NoSlidingExpiration);
Right now you've explicitly told the cache to do exactly the opposite of what you want it to do.
精彩评论