vb.net Asp.net 中的缓存(slidingExpiration 和 absoluteExpiration)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16542661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:35:17  来源:igfitidea点击:

Caching in Asp.net (slidingExpiration and absoluteExpiration)

c#asp.netvb.net

提问by user1187282

hy,

嘿,

How can use absoluteExpirationand slidingExpiration, if i specify both of them i get :absoluteExpiration must be DateTime.MaxValue or slidingExpiration must be timeSpan.Zero.

如何使用absoluteExpirationslidingExpiration,如果我同时指定它们,我会得到:absoluteExpiration 必须是 DateTime.MaxValue 或 SlideExpiration 必须是 timeSpan.Zero。

Cache.Insert("cachetest", value, Nothing,  ??,??;

Thanks,

谢谢,

回答by M4N

For sliding expiration, use this:

对于滑动到期,请使用:

Cache.Insert(key, value, Nothing,
             Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(10))

For absolute expiration, use this:

对于绝对过期,请使用:

Cache.Insert(key, value, Nothing,
             DateTime.Now.AddMinutes(2), Cache.NoSlidingExpiration)

回答by Klors

You must use one or the other. From the Microsoft documentation at http://msdn.microsoft.com/en-us/library/05kd8d77.aspx

您必须使用其中之一。来自http://msdn.microsoft.com/en-us/library/05kd8d77.aspx 上的 Microsoft 文档

absoluteExpiration

... If you are using absolute expiration, the slidingExpiration parameter must be NoSlidingExpiration.

slidingExpiration

...If you are using sliding expiration, the absoluteExpiration parameter must be NoAbsoluteExpiration.

绝对过期

...如果您使用的是绝对过期时间,则slidingExpiration 参数必须为NoSlidingExpiration。

滑动过期

...如果您使用的是滑动过期,则 absoluteExpiration 参数必须为 NoAbsoluteExpiration。