Browse Source

added log to PermissionStore

pull/2422/head
Halil İbrahim Kalkan 6 years ago
parent
commit
2c857f7dd3
  1. 14
      modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionStore.cs

14
modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionStore.cs

@ -1,4 +1,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
@ -11,12 +13,15 @@ namespace Volo.Abp.PermissionManagement
protected IDistributedCache<PermissionGrantCacheItem> Cache { get; }
protected ILogger<PermissionStore> Logger { get; set; }
public PermissionStore(
IPermissionGrantRepository permissionGrantRepository,
IDistributedCache<PermissionGrantCacheItem> cache)
{
PermissionGrantRepository = permissionGrantRepository;
Cache = cache;
Logger = NullLogger<PermissionStore>.Instance;
}
public async Task<bool> IsGrantedAsync(string name, string providerName, string providerKey)
@ -26,24 +31,33 @@ namespace Volo.Abp.PermissionManagement
protected virtual async Task<PermissionGrantCacheItem> GetCacheItemAsync(string name, string providerName, string providerKey)
{
Logger.LogDebug($"PermissionStore.GetCacheItemAsync: name={name}, providerName={providerName}, providerKey={providerKey}");
var cacheKey = CalculateCacheKey(name, providerName, providerKey);
var cacheItem = await Cache.GetAsync(cacheKey);
if (cacheItem != null)
{
Logger.LogDebug("Found in the cache.");
return cacheItem;
}
Logger.LogDebug("Not found in the cache, getting from the repository!");
cacheItem = new PermissionGrantCacheItem(
name,
await PermissionGrantRepository.FindAsync(name, providerName, providerKey) != null
);
Logger.LogDebug("Setting the cache item.");
await Cache.SetAsync(
cacheKey,
cacheItem
);
Logger.LogDebug("Finished setting the cache item.");
return cacheItem;
}

Loading…
Cancel
Save