/// <summary> /// Clears the cache. /// </summary> public void Clear( ) { if (InnerCache != null) { InnerCache.Clear( ); } if (!RedisCacheMemoryStoreSuppressionContext.IsSet(CacheName)) { _memoryStore.KeyDeletePrefix(CacheName); } }
/// <summary> /// Removes the specified key's cache value. /// </summary> /// <param name="key">The key.</param> /// <returns> /// True if the value was removed; False otherwise. /// </returns> public bool Remove(TKey key) { bool result = true; if (!RedisCacheMemoryStoreSuppressionContext.IsSet(CacheName)) { result = _memoryStore.KeyDelete(GetRedisKey(key)); } if (InnerCache != null) { result = InnerCache.Remove(key); } return(result); }
/// <summary> /// Attempts to retrieve the value with the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <returns> /// <c>true</c> if the cache contains the specified key; otherwise, <c>false</c>. /// </returns> public bool TryGetValue(TKey key, out TValue value) { RedisValue redisValue = RedisValue.Null; bool result = false; if (!RedisCacheMemoryStoreSuppressionContext.IsSet(CacheName)) { result = _memoryStore.TryGetString(GetRedisKey(key), out redisValue); } if (!result && InnerCache != null) { return(InnerCache.TryGetValue(key, out value)); } value = GetValue(redisValue); return(result); }
/// <summary> /// Removes the specified key's cache value. /// </summary> /// <param name="keys"></param> /// <returns> /// True if the value was removed; False otherwise. /// </returns> public IReadOnlyCollection <TKey> Remove(IEnumerable <TKey> keys) { TKey[] keyArray = keys.ToArray( ); bool[] result; if (!RedisCacheMemoryStoreSuppressionContext.IsSet(CacheName)) { RedisKey[] redisKeys = keyArray.Select(GetRedisKey).ToArray( ); result = _memoryStore.KeyDelete(redisKeys); } else { result = new bool[keyArray.Length]; for (int i = 0; i < result.Length; i++) { result[i] = true; } } if (InnerCache != null) { return(InnerCache.Remove(keyArray)); } var removedKeys = new List <TKey>( ); for (int i = 0; i < result.Length; i++) { if (result[i]) { removedKeys.Add(keyArray[i]); } } return(removedKeys.AsReadOnly( )); }