当前位置: 首页>>代码示例>>C#>>正文


C# CacheItemPolicy.RemovedCallback方法代码示例

本文整理汇总了C#中System.Runtime.Caching.CacheItemPolicy.RemovedCallback方法的典型用法代码示例。如果您正苦于以下问题:C# CacheItemPolicy.RemovedCallback方法的具体用法?C# CacheItemPolicy.RemovedCallback怎么用?C# CacheItemPolicy.RemovedCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Caching.CacheItemPolicy的用法示例。


在下文中一共展示了CacheItemPolicy.RemovedCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddOrGetExisting

		public override Object AddOrGetExisting(String key, Object value, CacheItemPolicy policy, String regionName = null)
		{
			if (value == null)
			{
				this.Delete(key);
				return (null);
			}
			else
			{
				var item = this.Get(key);

				if (item == null)
				{
					CacheItemRemovedCallback callback = (k, v, r) => policy.RemovedCallback(new CacheEntryRemovedArguments(this, (CacheEntryRemovedReason)(Int32)r, new CacheItem(k, v, regionName)));
					this.Add(key, value, policy.AbsoluteExpiration.LocalDateTime, policy.SlidingExpiration, (System.Web.Caching.CacheItemPriority)(Int32)policy.Priority, callback);
				}

				return (item);
			}
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.HttpCache,代码行数:20,代码来源:HttpCache.cs

示例2: AddOrInsert

        private object AddOrInsert(
            Func<string, object, CacheDependency, DateTime, TimeSpan, Web.Caching.CacheItemPriority, CacheItemRemovedCallback, object> action,
            string key, object value, CacheItemPolicy policy, string regionName = null
            )
        {
            var fileNames = new List<string>();
            foreach (var monitor in policy.ChangeMonitors) {
                var fileMonitor = monitor as FileChangeMonitor;
                if (fileMonitor == null)
                    throw new NotImplementedException();

                fileNames.AddRange(fileMonitor.FilePaths);
            }

            var dependency = fileNames.Count > 0
                           ? new CacheDependency(fileNames.ToArray())
                           : null;

            var callback = (CacheItemRemovedCallback)null;
            if (policy.RemovedCallback != null) {
                callback = (removedKey, removedValue, reason) => policy.RemovedCallback(
                    new CacheEntryRemovedArguments(this, reasonMap[reason], new CacheItem(removedKey, removedValue))
                );
            }

            return action(
                key, value, dependency,
                policy.AbsoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration ? policy.AbsoluteExpiration.UtcDateTime : Cache.NoAbsoluteExpiration,
                policy.SlidingExpiration != ObjectCache.NoSlidingExpiration ? policy.SlidingExpiration : Cache.NoSlidingExpiration,
                policy.Priority == Runtime.Caching.CacheItemPriority.NotRemovable
                    ? Web.Caching.CacheItemPriority.NotRemovable
                    : Web.Caching.CacheItemPriority.Default,
                callback
            );
        }
开发者ID:ashmind,项目名称:gallery,代码行数:35,代码来源:WebCache.cs


注:本文中的System.Runtime.Caching.CacheItemPolicy.RemovedCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。