2using System.Collections.Generic;
5using Microsoft.Extensions.Logging;
23 readonly ILogger<IdentityCache>
logger;
38 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
46 logger.LogTrace(
"Disposing...");
47 foreach (var cachedIdentity
in cachedIdentities.Select(x => x.Value).ToList())
48 cachedIdentity.Dispose();
54 ArgumentNullException.ThrowIfNull(user);
55 ArgumentNullException.ThrowIfNull(systemIdentity);
59 var uid = systemIdentity.
Uid;
60 logger.LogDebug(
"Caching system identity {0} of user {1}", uid, user.
Id);
64 logger.LogTrace(
"Expiring previously cached identity...");
69 systemIdentity.
Clone(),
73 logger.LogDebug(
"Expiring system identity cache for user {0}", user.Id);
74 lock (cachedIdentities)
75 cachedIdentities.Remove(user.Id.Value);
85 ArgumentNullException.ThrowIfNull(user);
88 return identity.SystemIdentity.
Clone();
89 throw new InvalidOperationException(
"Cached system identity has expired!");
virtual ? long Id
The ID of the entity.
ISystemIdentity LoadCachedIdentity(User user)
Attempt to load a cached ISystemIdentity. The cached ISystemIdentity or null if it doesn't exist or e...
readonly ILogger< IdentityCache > logger
The ILogger for the IdentityCache.
readonly IAsyncDelayer asyncDelayer
The IAsyncDelayer for the IdentityCache.
IdentityCache(IAsyncDelayer asyncDelayer, ILogger< IdentityCache > logger)
Initializes a new instance of the IdentityCache class.
readonly Dictionary< long, IdentityCacheObject > cachedIdentities
The map of Api.Models.EntityId.Ids to IdentityCacheObjects.
void CacheSystemIdentity(User user, ISystemIdentity systemIdentity, DateTimeOffset expiry)
Keep a user 's systemIdentity alive until an expiry time.
For keeping a specific ISystemIdentity alive for a period of time.
For caching ISystemIdentitys.
Represents a user on the current global::System.Runtime.InteropServices.OSPlatform.
ISystemIdentity Clone()
Clone the ISystemIdentity creating another copy that must have IDisposable.Dispose called on it.
string Uid
A unique identifier for the user.
For waiting asynchronously.