Table of Contents

Class RoleCache

Namespace
The.Security
Assembly
Instagile.dll

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

timeProvider TimeProvider

Properties

IsEmpty

True if no authorisation is cached or being looked up.

public bool IsEmpty { get; }

Property Value

bool

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

identity Identity
lifetime TimeSpan
lookup Func<AuthorisationResult>

Returns

AuthorisationResult

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

identity Identity
lifetime TimeSpan
lookup Func<Task<AuthorisationResult>>
cancellationToken CancellationToken

Returns

Task<AuthorisationResult>

Invalidate()

public void Invalidate()

Invalidate(Identity)

public void Invalidate(Identity identity)

Parameters

identity Identity

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

identity Identity
result AuthorisationResult

Returns

bool