确定应用程序缓存项何时超时?

时间:2022-06-23 20:49:34

In ASP.NET, when storing a value in the application cache with absolute expiry is there a method to retrieve the date/time when the item will expire? The application cache item will be refreshed if expired based on user requests.

在ASP.NET中,当在绝对到期的应用程序缓存中存储值时,是否有一种方法可以检索项目到期时的日期/时间?如果根据用户请求过期,将刷新应用程序缓存项。

3 个解决方案

#1


4  

There is a method signature on the HttContext.Cache object which allows you to specify a method to be called in the event that a Cached item is removed when you set a new Cache item.

HttContext.Cache对象上有一个方法签名,它允许您在设置新的Cache项时删除缓存项时指定要调用的方法。

Define yourself a method that'll allow you to process that information, whether you want it to re-submit the item to the Applcation Cache, email you about it, log it in the Event Log, whatever suits your needs.

定义一个允许您处理该信息的方法,无论您是希望它将项目重新提交到Applcation Cache,向您发送电子邮件,将其记录在事件日志中,以及适合您的需求。

Hope that helps, Pascal

希望有所帮助,Pascal

#2


1  

Not sure if I've understood your question right, but I'll give it a try: I believe there is no way to actually figure out, when a certain cache-item is going to expire. In most scenarios, I use a delegate passed in as a parameter (CacheItemRemovedCallback) when adding objects to the cache, so I get notified when the item gets kicked out.

我不确定我是否理解你的问题,但我会试一试:我相信当某个缓存项目即将到期时,没有办法真正弄明白。在大多数情况下,我在将对象添加到缓存时使用传入的委托作为参数(CacheItemRemovedCallback),因此当项目被踢出时我会收到通知。

Hope this helps a bit.

希望这个对你有帮助。

#3


0  

use the CacheItemRemovedCallback; your object may get kicked from the cache earlier than you expect anyway

使用CacheItemRemovedCallback;您的对象可能会比您预期的更早从缓存中踢出

#1


4  

There is a method signature on the HttContext.Cache object which allows you to specify a method to be called in the event that a Cached item is removed when you set a new Cache item.

HttContext.Cache对象上有一个方法签名,它允许您在设置新的Cache项时删除缓存项时指定要调用的方法。

Define yourself a method that'll allow you to process that information, whether you want it to re-submit the item to the Applcation Cache, email you about it, log it in the Event Log, whatever suits your needs.

定义一个允许您处理该信息的方法,无论您是希望它将项目重新提交到Applcation Cache,向您发送电子邮件,将其记录在事件日志中,以及适合您的需求。

Hope that helps, Pascal

希望有所帮助,Pascal

#2


1  

Not sure if I've understood your question right, but I'll give it a try: I believe there is no way to actually figure out, when a certain cache-item is going to expire. In most scenarios, I use a delegate passed in as a parameter (CacheItemRemovedCallback) when adding objects to the cache, so I get notified when the item gets kicked out.

我不确定我是否理解你的问题,但我会试一试:我相信当某个缓存项目即将到期时,没有办法真正弄明白。在大多数情况下,我在将对象添加到缓存时使用传入的委托作为参数(CacheItemRemovedCallback),因此当项目被踢出时我会收到通知。

Hope this helps a bit.

希望这个对你有帮助。

#3


0  

use the CacheItemRemovedCallback; your object may get kicked from the cache earlier than you expect anyway

使用CacheItemRemovedCallback;您的对象可能会比您预期的更早从缓存中踢出