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); } } }
private IUser GetUserFromCacheMap(string userName, string domain) { lock (padlock) { var cacheMapId = new CacheMapId(userName, domain); return(GetUserFromCacheMap(cacheMapId)); } }
private void RemoveUserFromCache(IUser user, CacheMapId cacheMapId) { if (user != null) { lock (padlock) { cachedUsers.Remove(user); cachedMap.Remove(cacheMapId); } } }
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)); } }
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); } }
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; } }
private IUser GetUserFromCacheMap(string userName, string domain) { lock(padlock) { var cacheMapId = new CacheMapId(userName, domain); return GetUserFromCacheMap(cacheMapId); } }
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); } }
private void RemoveUserFromCache(IUser user, CacheMapId cacheMapId) { if(user != null) { lock(padlock) { cachedUsers.Remove(user); cachedMap.Remove(cacheMapId); } } }
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); } } }