|
|
@ -24,7 +24,7 @@ namespace OpenIddict.Core |
|
|
public class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAuthorizationCache<TAuthorization>, IDisposable where TAuthorization : class |
|
|
public class OpenIddictAuthorizationCache<TAuthorization> : IOpenIddictAuthorizationCache<TAuthorization>, IDisposable where TAuthorization : class |
|
|
{ |
|
|
{ |
|
|
private readonly MemoryCache _cache; |
|
|
private readonly MemoryCache _cache; |
|
|
private readonly ConcurrentDictionary<string, Lazy<CancellationTokenSource>> _signals; |
|
|
private readonly ConcurrentDictionary<string, CancellationTokenSource> _signals; |
|
|
private readonly IOpenIddictAuthorizationStore<TAuthorization> _store; |
|
|
private readonly IOpenIddictAuthorizationStore<TAuthorization> _store; |
|
|
|
|
|
|
|
|
public OpenIddictAuthorizationCache( |
|
|
public OpenIddictAuthorizationCache( |
|
|
@ -36,7 +36,7 @@ namespace OpenIddict.Core |
|
|
SizeLimit = options.CurrentValue.EntityCacheLimit |
|
|
SizeLimit = options.CurrentValue.EntityCacheLimit |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
_signals = new ConcurrentDictionary<string, Lazy<CancellationTokenSource>>(StringComparer.Ordinal); |
|
|
_signals = new ConcurrentDictionary<string, CancellationTokenSource>(StringComparer.Ordinal); |
|
|
_store = resolver.Get<TAuthorization>(); |
|
|
_store = resolver.Get<TAuthorization>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -122,7 +122,7 @@ namespace OpenIddict.Core |
|
|
{ |
|
|
{ |
|
|
foreach (var signal in _signals) |
|
|
foreach (var signal in _signals) |
|
|
{ |
|
|
{ |
|
|
signal.Value.Value.Dispose(); |
|
|
signal.Value.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_cache.Dispose(); |
|
|
_cache.Dispose(); |
|
|
@ -596,11 +596,9 @@ namespace OpenIddict.Core |
|
|
throw new InvalidOperationException("The application identifier cannot be extracted."); |
|
|
throw new InvalidOperationException("The application identifier cannot be extracted."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (_signals.TryGetValue(identifier, out Lazy<CancellationTokenSource> signal)) |
|
|
if (_signals.TryRemove(identifier, out CancellationTokenSource signal)) |
|
|
{ |
|
|
{ |
|
|
signal.Value.Cancel(); |
|
|
signal.Cancel(); |
|
|
|
|
|
|
|
|
_signals.TryRemove(identifier, out signal); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -628,15 +626,9 @@ namespace OpenIddict.Core |
|
|
throw new InvalidOperationException("The authorization identifier cannot be extracted."); |
|
|
throw new InvalidOperationException("The authorization identifier cannot be extracted."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var signal = _signals.GetOrAdd(identifier, delegate |
|
|
var signal = _signals.GetOrAdd(identifier, _ => new CancellationTokenSource()); |
|
|
{ |
|
|
|
|
|
// Note: a Lazy<CancellationTokenSource> is used here to ensure only one CancellationTokenSource
|
|
|
|
|
|
// can be created. Not doing so would result in expiration signals being potentially linked to
|
|
|
|
|
|
// multiple sources, with a single one of them being eventually tracked and thus, cancelable.
|
|
|
|
|
|
return new Lazy<CancellationTokenSource>(() => new CancellationTokenSource()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return new CancellationChangeToken(signal.Value.Token); |
|
|
return new CancellationChangeToken(signal.Token); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|