void ClearCache(string cacheType) { if (cacheType == "me") { _cache.Remove(CacheKey()); nbWarning.Text = string.Format( "Your cache key has been cleared. Click <a href=\"{0}\">here</a> to reload the page.", new PageReference(RockPage.PageId).BuildUrl()); } else if (cacheType == "block") { string key = BlockCacheKey(); var keys = _cache.Where(kvp => kvp.Key.StartsWith(key)).Select(kvp => kvp.Key).ToList(); foreach (var k in keys) { _cache.Remove(k); } nbWarning.Text = string.Format( "{1} cache keys have been cleared. Click <a href=\"{0}\">here</a> to reload the page.", new PageReference(RockPage.PageId).BuildUrl(), keys.Count); } else { nbWarning.Text = "Cannot clear cache, unknown cache type."; } }
public bool Rename(string key, string newKey) { if (string.IsNullOrWhiteSpace(newKey)) { throw new ArgumentNullException("newKey"); } #if !CORE_CLR var orignalValue = _innerCache.Remove(key); if (orignalValue != null) { _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration); } return(orignalValue != null); #else object orignalValue; if (_innerCache.TryGetValue(key, out orignalValue)) { _innerCache.Remove(key); _innerCache.Set(newKey, orignalValue, new MemoryCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.MaxValue }); } return(orignalValue != null); #endif }
public override void Remove(string key) { #if !(NETCORE || CORE) _memoryCache.Remove(key); #else _memoryCache.Remove(key); #endif }
public static void CacheEkle(string key, object value, int expireAsMinute) { if (_cache.Any(x => x.Key == key)) { _cache.Remove(key); } _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute)); }
private async Task <T> GetOrSetMemory <T>(string key, TimeSpan timespan, Func <Task <T> > valueFactory) { var newValue = new Lazy <Task <T> >(valueFactory); var oldValue = _memorycache.AddOrGetExisting(key, newValue, DateTimeOffset.UtcNow.Add(timespan)) as Lazy <Task <T> >; try { return(await(oldValue ?? newValue).Value.ConfigureAwait(false)); } catch { _memorycache.Remove(key); return(default(T)); } }
public bool Rename(string key, string newKey) { if (string.IsNullOrWhiteSpace(newKey)) { throw new ArgumentNullException("newKey"); } var orignalValue = _innerCache.Remove(key); if (orignalValue != null) { _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration); } return(orignalValue != null); }
/// <summary> /// Delete cache value from key /// </summary> /// <param name="key"></param> public static void Delete(string key) { System.Runtime.Caching.MemoryCache memoryCache = System.Runtime.Caching.MemoryCache.Default; if (memoryCache.Contains(key)) { memoryCache.Remove(key); } }
public object Remove(string key) { if (key == null) { throw new ArgumentNullException("key"); } return(_cache.Remove(key)); }
/// <summary> /// Clears this instance or a partition, if specified. /// </summary> /// <param name="partition">The optional partition.</param> /// <param name="cacheReadMode">The cache read mode.</param> /// <returns>The number of items that have been removed.</returns> protected override long ClearInternal(string partition, CacheReadMode cacheReadMode = CacheReadMode.IgnoreExpiryDate) { // We need to make a snapshot of the keys, since the cache might be used by other // processes. Therefore, we start projecting all keys. var keys = _store.Select(x => x.Key); // Then, if a partition has been specified, we select only those keys that belong to that partition. if (partition != null) { keys = keys.Where(k => DeserializeCacheKey(k).Partition == partition); } // Now we take the snapshot of the keys. var keysArray = keys.ToArray(); // At last, we can remove them safely from the store itself. foreach (var key in keys) { _store.Remove(key); } return(keysArray.LongLength); }
public static T GetOrSet <T>(string key, Func <T> valueFactory, TimeSpan expiry) { try { var newValue = new Lazy <T>(valueFactory); var oldValue = _memorycache.AddOrGetExisting(key, newValue, DateTimeOffset.UtcNow.Add(expiry)) as Lazy <T>; return((oldValue ?? newValue).Value); } catch { _memorycache.Remove(key); return(default(T)); } }
private void SetCertCahe() { System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; if (tempmanagecache == null) { tempmanagecache = new List <CertCacheItem>(); } if (mcache.Get(cachetypename) != null) { mcache.Remove(cachetypename); } bool r = mcache.Add(cachetypename, tempmanagecache.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { mcache = null; } }
private void SetCache() { System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default; if (cacheapps == null) { cacheapps = new List <AppModel>(); } if (mcache.Get(getcachename) != null) { mcache.Remove(getcachename); } bool r = mcache.Add(getcachename, cacheapps.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes))); if (!r) { mcache = null; } }
/// <inheritdoc /> public void Remove(string key) { _memoryCache.Remove(key); }
public void Remove(string key) { cache.Remove(key); }
/// <summary> /// 删除缓存 /// </summary> /// <param name="key"></param> /// <returns></returns> public bool Delete(string key) { Cache.Remove(key); return(true); }
public void Remove(string key) { System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key)); _cache.Remove(key); }
/// <inheritdoc /> public bool Remove(string key) { return(key != null && cache.Remove(key) != null); }
public void SetIniValue(string initKey, string initValue) { m_DBCon.setIniValue(m_InitGroup, initKey, initValue); m_SettingsCache.Remove(initKey + "|" + initValue); }
public bool Remove(string key) { var item = _cache.Remove(key); return(item != null); }
public void Delete(string key) { _cache.Remove(key); }