Class CachingCorsPolicyService
- Namespace
- Fdyay.IdentityServer.Services
- Assembly
- Fdyay.IdentityServer.Core.dll
Answers from CorsPolicyCache where it can, and from the decorated service otherwise.
public sealed class CachingCorsPolicyService : ICorsPolicyService
- Inheritance
-
CachingCorsPolicyService
- Implements
- Inherited Members
Remarks
A CORS decision is taken on the preflight and again on the request that follows it, for every cross-origin call an application makes, so a policy service that reads a database is asked far more often than the data it reads changes. This is the decorator that stops that.
It caches a permission, and that has a cost the host is buying deliberately. InMemoryCorsPolicyService excludes disabled clients precisely so a decommissioned client's script stops reaching the protocol endpoints; with this in front of it, it stops reaching them up to one cache duration later. Nothing here is registered unless a host asks for it, the duration is theirs to choose, and Clear() ends the window early.
Constructors
CachingCorsPolicyService(ICorsPolicyService, CorsPolicyCache, TimeProvider, ILogger<CachingCorsPolicyService>)
A cache in front of inner.
public CachingCorsPolicyService(ICorsPolicyService inner, CorsPolicyCache cache, TimeProvider time, ILogger<CachingCorsPolicyService> logger)
Parameters
innerICorsPolicyServiceThe policy service asked when an origin is not held.
cacheCorsPolicyCacheWhere allowed origins are held, and for how long.
timeTimeProviderThe clock an entry's expiry is measured by.
loggerILogger<CachingCorsPolicyService>Where an answer from the cache is logged.
Methods
IsOriginAllowedAsync(string, CancellationToken)
Returns true if the origin is allowed.
public Task<bool> IsOriginAllowedAsync(string origin, CancellationToken cancellationToken = default)
Parameters
originstringcancellationTokenCancellationToken
Returns
Remarks
True from the cache while the origin is held; otherwise the inner service's answer, held only when it allows.