Class RoleCache
Stores the result of (expensive) authorisation lookups.
public sealed class RoleCache
- Inheritance
-
RoleCache
- Inherited Members
Remarks
Lookups are preregistered to support immediate invalidation and concurrent reuse.
Constructors
RoleCache(TimeProvider?)
public RoleCache(TimeProvider? timeProvider = null)
Parameters
timeProviderTimeProvider
Properties
IsEmpty
True if no authorisation is cached or being looked up.
public bool IsEmpty { get; }
Property Value
Methods
GetOrAdd(Identity, TimeSpan, Func<AuthorisationResult>)
Gets the cached roles and permissions for identity, or looks it up and caches it for lifetime (or until invalidated, if InfiniteTimeSpan).
public AuthorisationResult GetOrAdd(Identity identity, TimeSpan lifetime, Func<AuthorisationResult> lookup)
Parameters
identityIdentitylifetimeTimeSpanlookupFunc<AuthorisationResult>
Returns
Remarks
This is the sync version, which can't await an existing lookup, so if there is one it just does its own.
GetOrAddAsync(Identity, TimeSpan, Func<Task<AuthorisationResult>>, CancellationToken)
Gets the cached roles and permissions for identity, waits for a lookup in progress, or looks it up and caches it for lifetime (or until invalidated, if InfiniteTimeSpan).
public Task<AuthorisationResult> GetOrAddAsync(Identity identity, TimeSpan lifetime, Func<Task<AuthorisationResult>> lookup, CancellationToken cancellationToken)
Parameters
identityIdentitylifetimeTimeSpanlookupFunc<Task<AuthorisationResult>>cancellationTokenCancellationToken
Returns
Invalidate()
public void Invalidate()
Invalidate(Identity)
public void Invalidate(Identity identity)
Parameters
identityIdentity
TryGetValue(Identity, out AuthorisationResult)
Gets the roles and permissions for identity, if a lookup has completed since it was last invalidated and hasn't expired.
public bool TryGetValue(Identity identity, out AuthorisationResult result)
Parameters
identityIdentityresultAuthorisationResult