Delay for checking latest permissions

pull/13806/head
Halil İbrahim Kalkan 3 years ago
parent d9cf4d79c4
commit 84ae7e8e12

@ -78,22 +78,27 @@ public class DynamicPermissionDefinitionStore : IDynamicPermissionDefinitionStor
private async Task EnsureCacheIsUptoDateAsync()
{
/* TODO: Optimization note: May not check for a few seconds
* It is acceptable to get changes a few seconds after the last time the cache was updated.
*/
using (await StoreCache.SyncSemaphore.LockAsync())
{
if (StoreCache.LastCheckTime.HasValue &&
DateTime.Now.Subtract(StoreCache.LastCheckTime.Value).TotalSeconds < 30)
{
/* We get the latest permission with a small delay for optimization */
return;
}
var stampInDistributedCache = await GetOrSetStampInDistributedCache();
if (stampInDistributedCache == StoreCache.CacheStamp)
{
StoreCache.LastCheckTime = DateTime.Now;
return;
}
await UpdateInMemoryStoreCache();
StoreCache.CacheStamp = stampInDistributedCache;
StoreCache.LastCheckTime = DateTime.Now;
}
}

@ -21,6 +21,8 @@ public class DynamicPermissionDefinitionStoreInMemoryCache :
protected ISimpleStateCheckerSerializer StateCheckerSerializer { get; }
public SemaphoreSlim SyncSemaphore { get; } = new(1, 1);
public DateTime? LastCheckTime { get; set; }
public DynamicPermissionDefinitionStoreInMemoryCache(ISimpleStateCheckerSerializer stateCheckerSerializer)
{

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@ -11,6 +12,8 @@ public interface IDynamicPermissionDefinitionStoreInMemoryCache
SemaphoreSlim SyncSemaphore { get; }
DateTime? LastCheckTime { get; set; }
Task FillAsync(
List<PermissionGroupDefinitionRecord> permissionGroupRecords,
List<PermissionDefinitionRecord> permissionRecords);

Loading…
Cancel
Save