微软分布式缓存 AppFabric(Velocity)-开发篇(四)缓存通知
2011-08-19 15:01
573 查看
要使用缓存通知,要先配置缓存的通知服务已开启,在PowerShell工具中使用:
添加缓存通知须要两个步骤:
1.创建一个可以被缓存通知调用的方法,这个方法带有一个或多个通知类型选项。这个函数的参数必须和DataCacheNotificationCallback委托的参数相同。
2.用DataCache实例的 AddCacheLevelCallback, AddRegionLevelCallback或 AddItemLevelCallback其中的一个方法添加一个回调。
Step 1.DataCacheNotificationCallback参数
Step 2.添加回调
示例代码下载:VolocityDemo.rar
Set-CacheConfig命令将要开启通知的缓存通知开启。
添加缓存通知须要两个步骤:
1.创建一个可以被缓存通知调用的方法,这个方法带有一个或多个通知类型选项。这个函数的参数必须和DataCacheNotificationCallback委托的参数相同。
2.用DataCache实例的 AddCacheLevelCallback, AddRegionLevelCallback或 AddItemLevelCallback其中的一个方法添加一个回调。
Step 1.DataCacheNotificationCallback参数
//method invoked by notification "ndCacheLvlAllOps" public void myCacheLvlDelegate(string myCacheName,string myRegion, string myKey,DataCacheItemVersion itemVersion, DataCacheOperation OperationId,DataCacheNotificationDescriptor nd) { //display some of the delegate parameters Console.WriteLine("A cache-level notification was triggered!"); Console.WriteLine(" Cache: " + myCacheName); Console.WriteLine(" Region: " + myRegion); Console.WriteLine(" Key: " + myKey); Console.WriteLine(" Operation: " + OperationId.ToString()); Console.WriteLine(); }
Step 2.添加回调
DataCache dataCache = factory.GetCache("FirstCache"); //specify all possible item and region operations DataCacheOperation allCacheOperations = DataCacheOperation.AddItem | DataCacheOperation.ReplaceItem | DataCacheOperation.RemoveItem | DataCacheOperation.CreateRegion | DataCacheOperation.ClearRegion | DataCacheOperation.RemoveRegion; //add cache-level notification callback //all cache operations from a notifications-enabled cache DataCacheNotificationDescriptor ndCacheLvlAllOps = dataCache.AddCacheLevelCallback(allCacheOperations, myCacheLvlDelegate);
示例代码下载:VolocityDemo.rar
相关文章推荐
- 微软分布式缓存 AppFabric(Velocity)-开发篇(三)缓存日志
- 微软分布式缓存 AppFabric(Velocity)-开发篇(二)缓存的基础方法使用
- 微软分布式缓存 AppFabric(Velocity)学习-缓存概念(一)
- 微软分布式缓存 AppFabric(Velocity)-管理员指南
- 使用微软分布式缓存服务Velocity(Windows Server AppFabric Caching Service)
- 微软分布式缓存AppFabric(Velocity)学习-缓存概念(三)
- 微软分布式缓存AppFabric(Velocity)-开发篇(一)开发环境准备
- 微软分布式缓存 appfabric 安装部署
- 微软分布式缓存AppFabric(Velocity)学习-缓存概念(二)
- 使用微软分布式缓存服务Velocity Part 3
- 使用微软分布式缓存服务Velocity Part 1
- 使用微软分布式缓存服务Velocity Part 3
- 使用微软分布式缓存服务Velocity Part 1
- Velocity:微软的分布式内存缓存
- 微软高性能缓存AppFabric(二)使用
- 使用微软分布式缓存服务Velocity Part 1——转自 博客园 Terrylee
- Velocity:微软的分布式内存缓存
- 使用微软分布式缓存服务Velocity Part 1
- Velocity:微软的分布式内存缓存
- 使用微软分布式缓存服务Velocity Part 3——博客园 Terrylee