示例#1
0
        public override void AddUserToCache(IUser user)
        {
            if (user != null && MinutesInCache > 0)
            {
                lock (padlock) {
                    if (cachedUsers.Contains(user))
                    {
                        RemoveUserFromCache(user);
                    }

                    // Truncate cache if it has grown out of size.
                    if (MaxUsersInCache != 0 && cachedUsers.Count >= MaxUsersInCache)
                    {
                        TruncateCache();
                    }

                    user.MakeReadOnly();

                    var cacheMapId = new CacheMapId(user.UserName, user.Domain);
                    var cachedUser = new CachedUser(user);
                    cachedMap.Add(cacheMapId, cachedUser);
                    cachedUsers.Add(user);
                }
            }
        }
示例#2
0
 private IUser GetUserFromCacheMap(string userName, string domain)
 {
     lock (padlock) {
         var cacheMapId = new CacheMapId(userName, domain);
         return(GetUserFromCacheMap(cacheMapId));
     }
 }
示例#3
0
 private void RemoveUserFromCache(IUser user, CacheMapId cacheMapId)
 {
     if (user != null)
     {
         lock (padlock) {
             cachedUsers.Remove(user);
             cachedMap.Remove(cacheMapId);
         }
     }
 }
示例#4
0
 private IUser GetUserFromCacheMap(string userId)
 {
     lock (padlock) {
         var user = GetUser(userId);
         if (user == null)
         {
             return(null);
         }
         var cacheMapId = new CacheMapId(user.UserName, user.Domain);
         return(GetUserFromCacheMap(cacheMapId));
     }
 }
示例#5
0
        private IUser GetUserFromCacheMap(CacheMapId cacheMapId)
        {
            lock (cachedMap.SyncRoot) {
                if (!cachedMap.Contains(cacheMapId))
                {
                    return(null);
                }

                var cachedUser = (CachedUser)cachedMap[cacheMapId];

                // Remove user from cache if the cache time has expired
                if (cachedUser.DateCreated > DateTime.Now.AddMinutes(MinutesInCache))
                {
                    RemoveUserFromCache(cachedUser.User, cacheMapId);
                    return(null);
                }
                return(cachedUser.User);
            }
        }
示例#6
0
		private IUser GetUserFromCacheMap(CacheMapId cacheMapId) {
			lock(cachedMap.SyncRoot) {
				if(!cachedMap.Contains(cacheMapId)) {
					return null;
				}

				var cachedUser = (CachedUser)cachedMap[cacheMapId];

				// Remove user from cache if the cache time has expired
				if(cachedUser.DateCreated > DateTime.Now.AddMinutes(MinutesInCache)) {
					RemoveUserFromCache(cachedUser.User, cacheMapId);
					return null;
				}
				return cachedUser.User;
			}
		}
示例#7
0
		private IUser GetUserFromCacheMap(string userName, string domain) {
			lock(padlock) {
				var cacheMapId = new CacheMapId(userName, domain);
				return GetUserFromCacheMap(cacheMapId);
			}
		}
示例#8
0
		private IUser GetUserFromCacheMap(string userId) {
			lock(padlock) {
				var user = GetUser(userId);
				if(user == null) {
					return null;
				}
				var cacheMapId = new CacheMapId(user.UserName, user.Domain);
				return GetUserFromCacheMap(cacheMapId);
			}
		}
示例#9
0
		private void RemoveUserFromCache(IUser user, CacheMapId cacheMapId) {
			if(user != null) {
				lock(padlock) {
					cachedUsers.Remove(user);
					cachedMap.Remove(cacheMapId);
				}
			}
		}
示例#10
0
		public override void AddUserToCache(IUser user) {
			if(user != null && MinutesInCache > 0) {
				lock(padlock) {
					if(cachedUsers.Contains(user)) {
						RemoveUserFromCache(user);
					}

					// Truncate cache if it has grown out of size.
					if(MaxUsersInCache != 0 && cachedUsers.Count >= MaxUsersInCache) {
						TruncateCache();
					}

					user.MakeReadOnly();

					var cacheMapId = new CacheMapId(user.UserName, user.Domain);
					var cachedUser = new CachedUser(user);
					cachedMap.Add(cacheMapId, cachedUser);
					cachedUsers.Add(user);
				}
			}
		}