public void ClearCache() { if (IsDevelopment() || _env.IsStaging()) { _cache.Clear(); } }
/// <summary> /// 异步方式清除Reids中的数据 /// </summary> /// <returns></returns> protected virtual async Task ClearAsync() { _perRequestCacheManager.Clear(); foreach (var endPoint in _connectionWrapper.GetEndPoints()) { var server = _connectionWrapper.GetServer(endPoint); //使用下面注释的方法也可以实现,但是需要管理员权限 - ",allowAdmin=true" //server.FlushDatabase(); //所以通过手动删除所有的元素 var keys = server.Keys(database: _db.Database); //始终保留保护key的数据 keys = keys.Where(key => !key.ToString().Equals(OarmsCachingDefaults.RedisDataProtectionKey, StringComparison.OrdinalIgnoreCase)); await _db.KeyDeleteAsync(keys.ToArray()); } }