Authentication Scheme Caching
Due to how ASP.NET Core handles authentication libraries, your implementation of IAuthenticationSchemeStore
will be called multiple times per request. As a result, without a layer of caching, you may start to experience performance issues.
A basic caching layer is available in the Rsk.DynamicAuthenticationProviders
library and can be registered with:
services.AddDynamicProviders()
.AddCaching();
IAuthenticationSchemeCache
By default, an in-memory store is used. To replace this, simply implement and register your own implementation of IAuthenticationSchemeCache
.
public interface IAuthenticationSchemeCache
{
Task<IEnumerable<AuthenticationScheme>> GetAll();
Task Clear();
}
Cache Invalidation
To invalidate the cache you can either call the Clear
method on your IAuthenticationSchemeCache
implementation or, if you are using the default caching implementation, turn down the CacheDuration
in DynamicAuthenticationSchemeOptions
.
This is necessary if you need to update authentication scheme options that have already been loaded and cached.