缓存过期事件asp.net企业库 [英] Cache Expiration event asp.net enterprise library

查看:79
本文介绍了缓存过期事件asp.net企业库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有它每次缓存项是关于太得到它时,缓存项越来越expired.I正在使用企业库在asp.net缓存过期上调或任何事件发生的任何事件。我想一些数据存储在我的数据库时,高速缓存即将获得,而不是过期调用一个函数或调用一个事件我自己,我想使用的是被用来冲洗或处理缓存中的项目已管理的缓存库事件的。

I wanted to know if there is any event which occurs each time a cache item is about too get expired or any event which is raised when a cache item is getting expired.I am using enterprise library in asp.net for caching.I want to store some data in my database when a cache is about to get expired instead of calling a function or invoking an event myself I was thinking of using the already managed cache library event which is being used to flush or dispose cache items.

推荐答案

假设你正在使用的缓存应用程序块,那么你指定一个回调委托当您添加项目到缓存中。

Assuming you're using the Caching Application Block then you specify a callback delegate when you add items to the cache.

从缓存中的项目的拆除接到通知要求您指定的调用Add方法

Receiving notification of an item's removal from the cache requires that you specify the class implementing ICacheItemRefreshAction on the call to the Add method

您需要提供实现类 ICacheItemRefreshAction

[Serializable]
public class ProductCacheRefreshAction : ICacheItemRefreshAction
{
  public void Refresh(string key, object expiredValue, CacheItemRemovedReason removalReason)
  {
    // Item has been removed from cache. Perform desired actions here, based on
    // the removal reason (for example, refresh the cache with the item).
  }
}

正如你所看到的,当一个项目被删除,该刷新()方法被调用与键的的正在删除对象。你只需要在 expiredObject 参数转换为正确的类型,并安排其存储到数据库中。

As you can see, when an item is removed, this Refresh() method is called with the key and the object that's being removed. You just need to cast the expiredObject parameter to the correct type and arrange to have it stored to the database.

由于记录在这里:的http:// MSDN .microsoft.com / EN-US /库/ ff664621(v = PandP.50)的.aspx

这篇关于缓存过期事件asp.net企业库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆