Beispiel #1
0
        /// <summary>
        /// Removes an item from the cache
        /// </summary>
        /// <param name="key">Cache key</param>
        /// <param name="partitionName">
        /// Optional value for the name of a partition in the application cache. Partitions can be a good way to categorize or group
        /// certain types of items in the cache together.
        /// </param>
        public async Task RemoveAsync(string key, string partitionName = "")
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            // Remove it from the partition
            if (string.IsNullOrEmpty(partitionName)) // Remove the object from regular cache
            {
                await _redisDatabase.KeyDeleteAsync(key).ConfigureAwait(false);
            }
            else // Else remove the object from the redis hash set.
            {
                var partitionKey = ComposePartitionKey(partitionName);
                await _redisDatabase.HashDeleteAsync(partitionKey, key).ConfigureAwait(false);

                var timeoutPartitionKey = ComposeTimeoutPartitionKey(partitionName);
                await _redisDatabase.HashDeleteAsync(timeoutPartitionKey, key).ConfigureAwait(false);
            }
        }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public async Task <bool> KeyDeleteAsync(string key)
 {
     return(await _database.KeyDeleteAsync(GetKeyForRedis(key)));
 }