protected virtual async Task <List <(string Key, bool IsGranted)> > SetCacheItemsAsync(string providerName, string providerKey, List <string> notCacheKeys) { var permissions = _permissionDefinitionManager.GetPermissions().Where(x => notCacheKeys.Any(k => GetPermissionInfoFormCacheKey(k).Name == x.Name)).ToList(); _logger.LogDebug("Getting not cache granted permissions from the repository for this provider name,key: {providerName},{providerKey}", providerName, providerKey); var grantedPermissionsHashSet = new HashSet <string>((await _repository.GetListAsync(notCacheKeys.Select(k => GetPermissionInfoFormCacheKey(k).Name).ToArray(), providerName, providerKey)).Select(p => p.Name)); _logger.LogDebug("Setting the cache items. Count: {permissionsCount}", permissions.Count); List <(string Key, bool IsGranted)>?cacheItems = new(); foreach (PermissionDefinition?permission in permissions) { var isGranted = grantedPermissionsHashSet.Contains(permission.Name); cacheItems.Add((string.Format(CacheKeyFormat, providerName, providerKey, permission.Name), isGranted)); } List <Task> setCacheItemTasks = new(); foreach ((string Key, bool IsGranted) in cacheItems) { setCacheItemTasks.Add(_distributedCache.SetStringAsync(Key, IsGranted.ToString())); } await Task.WhenAll(setCacheItemTasks); _logger.LogDebug("Finished setting the cache items. Count: {permissionsCount}", permissions.Count); return(cacheItems); }
protected virtual async Task <(string Key, bool IsGranted)> SetCacheItemsAsync(string providerName, string providerKey, string currentName) { var permissions = _permissionDefinitionManager.GetPermissions(); _logger.LogDebug("Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}", providerName, providerKey); var grantedPermissionsHashSet = new HashSet <string>((await _repository.GetListAsync(providerName, providerKey)).Select(p => p.Name)); _logger.LogDebug("Setting the cache items. Count: {permissionsCount}", permissions.Count); var cacheItems = new List <(string Key, bool IsGranted)>(); bool currentResult = false; foreach (var permission in permissions) { var isGranted = grantedPermissionsHashSet.Contains(permission.Name); cacheItems.Add((string.Format(CacheKeyFormat, providerName, providerKey, permission.Name), isGranted)); if (permission.Name == currentName) { currentResult = isGranted; } } List <Task> setCacheItemTasks = new(); foreach ((string Key, bool IsGranted) in cacheItems) { setCacheItemTasks.Add(_distributedCache.SetStringAsync(Key, IsGranted.ToString())); } await Task.WhenAll(setCacheItemTasks); _logger.LogDebug("Finished setting the cache items. Count: {permissionsCount}", permissions.Count); return(string.Format(CacheKeyFormat, providerName, providerKey, currentName), currentResult); }