本文整理汇总了C#中CacheItemRemovedCallback类的典型用法代码示例。如果您正苦于以下问题:C# CacheItemRemovedCallback类的具体用法?C# CacheItemRemovedCallback怎么用?C# CacheItemRemovedCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheItemRemovedCallback类属于命名空间,在下文中一共展示了CacheItemRemovedCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set
/// <summary>
/// 添加缓存 (绝对有效期)
/// </summary>
/// <param name="cacheKey">缓存键值</param>
/// <param name="cacheValue">缓存内容</param>
/// <param name="timeout">绝对有效期(单位: 秒)</param>
public static void Set(string cacheKey, object cacheValue, int timeout)
{
if (string.IsNullOrEmpty(cacheKey))
{
return;
}
if (null == cacheValue)
{
Remove(cacheKey);
return;
}
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);
if (timeout <= 0)
{
cache.Insert(cacheKey, cacheValue, null, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.High, callBack);
}
else
{
cache.Insert(cacheKey, cacheValue, null, DateTime.Now.AddSeconds(timeout), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, callBack);
}
}
示例2: BindSignal
private void BindSignal(string virtualPath, CacheItemRemovedCallback callback)
{
string key = _prefix + virtualPath;
//PERF: Don't add in the cache if already present. Creating a "CacheDependency"
// object (below) is actually quite expensive.
if (HostingEnvironment.Cache.Get(key) != null)
return;
var cacheDependency = HostingEnvironment.VirtualPathProvider.GetCacheDependency(
virtualPath,
new[] { virtualPath },
_clock.UtcNow);
Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
HostingEnvironment.Cache.Add(
key,
virtualPath,
cacheDependency,
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable,
callback);
}
示例3: CacheBuildResult
internal override void CacheBuildResult(string cacheKey, BuildResult result, long hashCode, DateTime utcStart)
{
if (!BuildResultCompiledType.UsesDelayLoadType(result))
{
ICollection virtualPathDependencies = result.VirtualPathDependencies;
CacheDependency dependencies = null;
if (virtualPathDependencies != null)
{
dependencies = result.VirtualPath.GetCacheDependency(virtualPathDependencies, utcStart);
if (dependencies != null)
{
result.UsesCacheDependency = true;
}
}
if (result.CacheToMemory)
{
CacheItemPriority normal;
BuildResultCompiledAssemblyBase base2 = result as BuildResultCompiledAssemblyBase;
if (((base2 != null) && (base2.ResultAssembly != null)) && !base2.UsesExistingAssembly)
{
string assemblyCacheKey = BuildResultCache.GetAssemblyCacheKey(base2.ResultAssembly);
Assembly assembly = (Assembly) this._cache.Get(assemblyCacheKey);
if (assembly == null)
{
this._cache.UtcInsert(assemblyCacheKey, base2.ResultAssembly, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
}
CacheDependency dependency2 = new CacheDependency(0, null, new string[] { assemblyCacheKey });
if (dependencies != null)
{
AggregateCacheDependency dependency3 = new AggregateCacheDependency();
dependency3.Add(new CacheDependency[] { dependencies, dependency2 });
dependencies = dependency3;
}
else
{
dependencies = dependency2;
}
}
string memoryCacheKey = GetMemoryCacheKey(cacheKey);
if (result.IsUnloadable)
{
normal = CacheItemPriority.Normal;
}
else
{
normal = CacheItemPriority.NotRemovable;
}
CacheItemRemovedCallback onRemoveCallback = null;
if (result.ShutdownAppDomainOnChange || (result is BuildResultCompiledAssemblyBase))
{
if (this._onRemoveCallback == null)
{
this._onRemoveCallback = new CacheItemRemovedCallback(this.OnCacheItemRemoved);
}
onRemoveCallback = this._onRemoveCallback;
}
this._cache.UtcInsert(memoryCacheKey, result, dependencies, result.MemoryCacheExpiration, result.MemoryCacheSlidingExpiration, normal, onRemoveCallback);
}
}
}
示例4: AddCache
/// <summary>
/// 建立缓存,并在移除时执行事件
/// </summary>
public static object AddCache(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemovedCallback)
{
if (HttpRuntime.Cache[key] == null && value != null)
return HttpRuntime.Cache.Add(key, value, null, absoluteExpiration, slidingExpiration, priority, onRemovedCallback);
else
return null;
}
示例5: Set
/// <summary>
/// 本地缓存写入,包括分钟,是否绝对过期及缓存过期的回调
/// </summary>
/// <param name="name">key</param>
/// <param name="value">value</param>
/// <param name="minutes"缓存分钟></param>
/// <param name="isAbsoluteExpiration">是否绝对过期</param>
/// <param name="onRemoveCallback">缓存过期回调</param>
public static void Set(string name, object value, int minutes, bool isAbsoluteExpiration, CacheItemRemovedCallback onRemoveCallback)
{
if (isAbsoluteExpiration)
HttpRuntime.Cache.Insert(name, value, null, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration, CacheItemPriority.Normal, onRemoveCallback);
else
HttpRuntime.Cache.Insert(name, value, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(minutes), CacheItemPriority.Normal, onRemoveCallback);
}
示例6: Insert
public void Insert(string key, object value, CacheDependency dependencies,
DateTime absoluteExpiration, TimeSpan slidingExpiration,
CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
{
_cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration,
priority, onRemoveCallback);
}
示例7: AddTask
private void AddTask(string name, int seconds)
{
_onCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(name, seconds, null,
DateTime.Now.AddSeconds(seconds), System.Web.Caching.Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
示例8: CacheEntry
internal CacheEntry (Cache objManager, string strKey, object objItem,CacheDependency objDependency,
CacheItemRemovedCallback eventRemove, DateTime dtExpires, TimeSpan tsSpan,
long longMinHits, bool boolPublic, CacheItemPriority enumPriority )
{
if (boolPublic)
_enumFlags |= Flags.Public;
_strKey = strKey;
_objItem = objItem;
_objCache = objManager;
_onRemoved += eventRemove;
_enumPriority = enumPriority;
_ticksExpires = dtExpires.ToUniversalTime ().Ticks;
_ticksSlidingExpiration = tsSpan.Ticks;
// If we have a sliding expiration it overrides the absolute expiration (MS behavior)
// This is because sliding expiration causes the absolute expiration to be
// moved after each period, and the absolute expiration is the value used
// for all expiration calculations.
if (tsSpan.Ticks != Cache.NoSlidingExpiration.Ticks)
_ticksExpires = DateTime.UtcNow.AddTicks (_ticksSlidingExpiration).Ticks;
_objDependency = objDependency;
if (_objDependency != null)
// Add the entry to the cache dependency handler (we support multiple entries per handler)
_objDependency.Changed += new CacheDependencyChangedHandler (OnChanged);
_longMinHits = longMinHits;
}
示例9: Insert
public override void Insert(string cacheKey, object itemToCache, DNNCacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback)
{
//onRemoveCallback += ItemRemovedCallback;
//Call base class method to add obect to cache
base.Insert(cacheKey, itemToCache, dependency, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
}
示例10: CachedLifetime
public static IExpressionRegistration CachedLifetime(this IExpressionRegistration registration, TimeSpan slidingExpiration, CacheDependency dependency = null, CacheItemPriority itemPriority = CacheItemPriority.Default, CacheItemRemovedCallback itemRemovedCallback = null)
{
if (registration == null)
throw new ArgumentNullException("registration");
registration.SetLifetime(new CachedLifetime(slidingExpiration, dependency, itemPriority, itemRemovedCallback));
return registration;
}
示例11: Add
public static void Add(string key, object o, int time, TimeSpan timespan, CacheItemPriority priority, CacheItemRemovedCallback callback)
{
if (o == null)
{
return;
}
_cache.Insert(key, o, null, DateTime.Now.AddSeconds(time), timespan, priority, callback);
}
示例12: Initialize
public override void Initialize(string name, NameValueCollection config)
{
if (String.IsNullOrEmpty(name))
name = "InProc Session State Provider";
base.Initialize(name, config);
_callback = new CacheItemRemovedCallback(this.OnCacheItemRemoved);
}
示例13: RemoveFileWithDelayInternal
static void RemoveFileWithDelayInternal(string fileKey, object fileData, int delay, CacheItemRemovedCallback removeAction) {
string key = RemoveTaskKeyPrefix + fileKey;
if(HttpRuntime.Cache[key] == null) {
DateTime absoluteExpiration = DateTime.UtcNow.Add(new TimeSpan(0, delay, 0));
HttpRuntime.Cache.Insert(key, fileData, null, absoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, removeAction);
}
}
示例14: AddObject
/// <summary>
/// 加入当前对象到缓存中
/// </summary>
/// <param name="objId">key for the object</param>
/// <param name="o">object</param>
public void AddObject(string objId, object o)
{
if (objId == null || objId.Length == 0 || o == null)
return;
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);
webCacheforfocus.Insert(objId, o, null, DateTime.Now.AddMinutes(TimeOut), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, callBack);
}
示例15: Insert
public void Insert(string Key, object Obj, CacheDependency Dependency, double TimeOut, TimeSpan SlidingExpiration, CacheItemPriority Priority, CacheItemRemovedCallback RemovedCallback)
{
if ((Obj != null)) {
Cache Cache = HttpRuntime.Cache;
if (Cache [Key] == null) {
Cache.Insert(Key, RuntimeHelpers.GetObjectValue(Obj), Dependency, DateTime.Now.AddSeconds(TimeOut), SlidingExpiration, Priority, RemovedCallback);
}
}
}