public void Add(string key, object o, TimeSpan?expiry, When when) { lock (_lockObj) { if (when == When.Exists && !_cache.Contains(key)) { return; } if (when == When.NotExists && _cache.Contains(key)) { return; } _cache.Remove(key); CacheItemPolicy policy = new CacheItemPolicy(); if (expiry.HasValue && expiry.Value != default(TimeSpan)) { //Store the ttl separately _ttls[key] = policy.AbsoluteExpiration = DateTime.UtcNow.Add(expiry.Value); } else { _ttls[key] = null; } System.Diagnostics.Debug.WriteLine("Adding key to mem cache: " + key); _cache.Add(key, o, policy); } }
public void Remove(Guid id) { #if NET461 _cache.Remove(id.ToString()); #else _cache.Remove(id); #endif }
public void Remove(string id) { #if NET451 _cache.Remove(id); #else _cache.Remove(id); #endif }
public Task Remove(string id) { #if NET451 _cache.Remove(id); #else _cache.Remove(id); #endif return(Task.FromResult(0)); }
public Task Remove(Guid id) { #if NET452 _cache.Remove(id.ToString()); #else _cache.Remove(id); #endif return(Task.FromResult(0)); }
public override void Add(object objectToCache, string key) { if (objectToCache == null) { _cache.Remove(key); } else { _cache[key] = objectToCache; } }
public void Remove(string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException("key", "the key is null or empty."); } string cacheKey = GetCacheKey(key); if (cache.Contains(key, regionName)) { cache.Remove(cacheKey, regionName); } }
protected override void RemoveInternal(string key) { if (Exists(key)) { _cache.Remove(key); } }
public void Clear(string key) { if (_cache.Contains(key)) { _cache.Remove(key); } }
public void Put(object key, object value) { if (key == null) { throw new ArgumentNullException("key", "null key not allowed"); } if (value == null) { throw new ArgumentNullException("value", "null value not allowed"); } var cacheKey = GetCacheKey(key); if (cache[cacheKey] != null) { if (log.IsDebugEnabled) { log.Debug(string.Format("updating value of key '{0}' to '{1}'.", cacheKey, value)); } // Remove the key to re-add it again below cache.Remove(cacheKey); } else { if (log.IsDebugEnabled) { log.Debug(string.Format("adding new data: key={0}&value={1}", cacheKey, value)); } } if (!rootCacheKeyStored) { StoreRootCacheKey(); } var entry = new DictionaryEntry(key, value); var cacheItemPolicy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.Add(expiration), SlidingExpiration = ObjectCache.NoSlidingExpiration }; cache.Add(cacheKey, entry, cacheItemPolicy); }
/// <summary> /// 移除缓存 /// </summary> /// <param name="key">key</param> /// <param name="prefix">前缀</param> public void Remove(string key) { if (string.IsNullOrWhiteSpace(key)) { new NullReferenceException("Remove方法的{key}参数值为空。"); } cache.Remove(key); }
protected override Task RemoveKeysAsync(IEnumerable <string> keys, string partition = null) { if (!string.IsNullOrEmpty(partition)) { keys = keys.Select(key => $"${partition}$|{key}").ToList(); } foreach (var key in keys) { _client.Remove(key, CacheEntryRemovedReason.Removed, null); } return(Task.CompletedTask); }
public void Save <T>(T aggregate, int?expectedVersion = null) where T : AggregateRoot { var idstring = aggregate.Id.ToString(); try { lock (_locks.GetOrAdd(idstring, _ => new object())) { if (aggregate.Id != Guid.Empty && !IsTracked(aggregate.Id)) { _cache.Add(idstring, aggregate, _policyFactory.Invoke()); } _repository.Save(aggregate, expectedVersion); } } catch (Exception) { _cache.Remove(idstring); throw; } }
/// <summary> /// Stores an object identified by a unique key in cache. /// </summary> /// <param name="correlationId"></param> /// <param name="key">Unique key identifying a data object.</param> /// <param name="value">The data object to store.</param> /// <param name="timeout">Time to live for the object in milliseconds.</param> public async Task <object> StoreAsync(string correlationId, string key, object value, long timeout) { if (key == null) { throw new ArgumentNullException(nameof(key)); } // Shortcut to remove entry from the cache if (value == null) { if (_standardCache.Contains(key)) { _standardCache.Remove(key); } return(null); } if (MaxSize <= _standardCache.GetCount()) { lock (_lock) { if (MaxSize <= _standardCache.GetCount()) { _standardCache.Trim(5); } } } timeout = timeout > 0 ? timeout : Timeout; _standardCache.Set(key, value, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMilliseconds(timeout) }); return(await Task.FromResult(value)); }
/// <summary> /// Remove key on the MemoryCache server cache /// </summary> /// <param name="key">Key of object</param> public override void Remove(string key) { Cache.Remove(key); }
protected override void RemoveCache(string key) => _memoryCache.Remove(key);
public bool Remove(string key) => FBackend.Remove(key) != null;
public void Remove(string key) { cache.Remove(key); }
/// <summary> /// Deleting value from cache /// </summary> /// <param name="key">Cache key</param> public static void ClearCache(string key) { cache.Remove(key); }
void OnMonitorChanged(object state) { owner.Remove(this); }
public void TestNullKeyRemove() { ICache cache = new MemoryCache(); Assert.Throws<ArgumentNullException>(() => cache.Remove(null)); }
/// <summary> /// 移除指定缓存项 /// </summary> /// <param name="key">Key</param> public bool Remove(string key) { mc.Remove(key); return(true); }
/// <summary> /// Remove entry from cache. /// </summary> /// <typeparam name="T">item type</typeparam> /// <param name="key">item key</param> /// <returns></returns> public bool Remove <T>(NonNullable <string> key) where T : class { return(_cache.Remove(CacheKey <T>(key)) != null); }
/// <summary> /// 从缓存中移除某个缓存项。 /// </summary> /// <param name="key">要移除的缓存项的唯一标识符。</param> public virtual void Remove(string key) { _cache.Remove(key); }
public static object Remove(string key) { return(_cache.Remove(key)); }
/// <summary> /// Remove a cached object /// </summary> /// <param name="key"></param> public void Expire(string key) { _cache.Remove(key); }