Пример #1
0
        /// <inheritdoc />
        public void CacheSystemIdentity(User user, ISystemIdentity systemIdentity, DateTimeOffset expiry)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (systemIdentity == null)
            {
                throw new ArgumentNullException(nameof(systemIdentity));
            }
            lock (cachedIdentities)
            {
                var uid = systemIdentity.Uid;
                logger.LogDebug("Caching system identity {0} of user {1}", uid, user.Id);

                if (cachedIdentities.TryGetValue(user.Id.Value, out var identCache))
                {
                    logger.LogTrace("Expiring previously cached identity...");
                    identCache.Dispose();                     // also clears it out
                }

                identCache = new IdentityCacheObject(systemIdentity.Clone(), asyncDelayer, () =>
                {
                    logger.LogDebug("Expiring system identity cache for user {1}", uid, user.Id);
                    lock (cachedIdentities)
                        cachedIdentities.Remove(user.Id.Value);
                }, expiry);
                cachedIdentities.Add(user.Id.Value, identCache);
            }
        }
Пример #2
0
 /// <inheritdoc />
 public void CacheSystemIdentity(User user, ISystemIdentity systemIdentity, DateTimeOffset expiry)
 {
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     if (systemIdentity == null)
     {
         throw new ArgumentNullException(nameof(systemIdentity));
     }
     lock (cachedIdentities)
     {
         if (cachedIdentities.TryGetValue(user.Id, out var identCache))
         {
             identCache.Dispose();                       //also clears it out
         }
         identCache = new IdentityCacheObject(systemIdentity.Clone(), () =>
         {
             lock (cachedIdentities)
                 cachedIdentities.Remove(user.Id);
         }, expiry);
         cachedIdentities.Add(user.Id, identCache);
     }
 }