本文整理汇总了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);
}
}
示例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
);
}