remove semaphore
This commit is contained in:
@@ -20,7 +20,6 @@ public class MareConfigurationServiceClient<T> : IConfigurationService<T> where
|
|||||||
private readonly ILogger<MareConfigurationServiceClient<T>> _logger;
|
private readonly ILogger<MareConfigurationServiceClient<T>> _logger;
|
||||||
private readonly GrpcClientFactory _grpcClientFactory;
|
private readonly GrpcClientFactory _grpcClientFactory;
|
||||||
private readonly string _grpcClientName;
|
private readonly string _grpcClientName;
|
||||||
private static readonly SemaphoreSlim _readLock = new(1);
|
|
||||||
|
|
||||||
public MareConfigurationServiceClient(ILogger<MareConfigurationServiceClient<T>> logger, IOptions<T> config, GrpcClientFactory grpcClientFactory, string grpcClientName)
|
public MareConfigurationServiceClient(ILogger<MareConfigurationServiceClient<T>> logger, IOptions<T> config, GrpcClientFactory grpcClientFactory, string grpcClientName)
|
||||||
{
|
{
|
||||||
@@ -40,10 +39,8 @@ public class MareConfigurationServiceClient<T> : IConfigurationService<T> where
|
|||||||
bool isRemote = prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), inherit: true).Any();
|
bool isRemote = prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), inherit: true).Any();
|
||||||
if (isRemote)
|
if (isRemote)
|
||||||
{
|
{
|
||||||
_readLock.Wait();
|
|
||||||
if (_cachedRemoteProperties.TryGetValue(key, out var existingEntry))
|
if (_cachedRemoteProperties.TryGetValue(key, out var existingEntry))
|
||||||
{
|
{
|
||||||
_readLock.Release();
|
|
||||||
return (T1)_cachedRemoteProperties[key].Value;
|
return (T1)_cachedRemoteProperties[key].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +64,6 @@ public class MareConfigurationServiceClient<T> : IConfigurationService<T> where
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_readLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = prop.GetValue(_config);
|
var value = prop.GetValue(_config);
|
||||||
@@ -103,10 +96,8 @@ public class MareConfigurationServiceClient<T> : IConfigurationService<T> where
|
|||||||
bool isRemote = prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), inherit: true).Any();
|
bool isRemote = prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), inherit: true).Any();
|
||||||
if (isRemote)
|
if (isRemote)
|
||||||
{
|
{
|
||||||
_readLock.Wait();
|
if (_cachedRemoteProperties.TryGetValue(key, out var existingEntry))
|
||||||
if (_cachedRemoteProperties.TryGetValue(key, out var existingEntry) && existingEntry.Inserted > DateTime.Now - TimeSpan.FromMinutes(60))
|
|
||||||
{
|
{
|
||||||
_readLock.Release();
|
|
||||||
return (T1)_cachedRemoteProperties[key].Value;
|
return (T1)_cachedRemoteProperties[key].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +121,6 @@ public class MareConfigurationServiceClient<T> : IConfigurationService<T> where
|
|||||||
throw new KeyNotFoundException(key);
|
throw new KeyNotFoundException(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_readLock.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = prop.GetValue(_config);
|
var value = prop.GetValue(_config);
|
||||||
|
|||||||
Reference in New Issue
Block a user