简体   繁体   English

在Asp.net中缓存

[英]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. 我已将缓存设置为在10秒后过期,并且提到了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 visited the page, in the 9th second another user visits the application. 现在,假设第一个用户访问了该页面之后,在第9个第二个用户访问了该应用程序。 In this case the Cache doens't get expired at the 10th second and extends itself to the next 10 seconds. 在这种情况下,Cache不会在第10秒过期,并将自身延伸到接下来的10秒。 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. 我发现Cache只有在应用程序空闲10秒后才会过期。 That is, if there is no hit to the site for 10 seconds. 也就是说,如果网站没有被击中10秒钟。

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. 无论任何用户仍在访问该页面还是该应用程序处于空闲状态,我如何才能使缓存每10秒过期一次。

Thanks in advance. 提前致谢。

Well then use NoSlidingExpiration instead of NoAbsoluteExpiration and give it a timespan for absolute expiration. 然后使用NoSlidingExpiration而不是NoAbsoluteExpiration并给它一个绝对到期的时间跨度。

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. 现在你明确地告诉缓存完全与你想要它做的完全相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM