move UserAccountCache access locking to its methods and not callers.

melanie
UbitUmarov 2016-11-09 20:09:49 +00:00
parent 924c5fb55e
commit 1e1d0d8204
3 changed files with 54 additions and 55 deletions

View File

@ -154,13 +154,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = UserAccountService.GetUserAccount(scopeID, userID);
lock(m_Cache)
m_Cache.Cache(userID, account);
return account;
@ -170,14 +168,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = UserAccountService.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account);
return account;
@ -201,7 +197,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
if(UUID.TryParse(id, out uuid))
{
lock(m_Cache)
account = m_Cache.Get(uuid, out inCache);
if (inCache)
ret.Add(account);
@ -220,7 +215,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
foreach(UserAccount acc in ext)
{
if(acc != null)
lock(m_Cache)
m_Cache.Cache(acc.PrincipalID, acc);
}
}

View File

@ -128,7 +128,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
// flags, title, etc. And country, don't forget country!
private void OnNewClient(IClientAPI client)
{
lock(m_Cache)
m_Cache.Remove(client.Name);
}
@ -138,17 +137,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, userID);
if(account != null)
{
lock(m_Cache)
m_Cache.Cache(userID, account);
}
return account;
}
@ -156,17 +152,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
bool inCache = false;
UserAccount account;
lock(m_Cache)
account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
{
lock(m_Cache)
m_Cache.Cache(account.PrincipalID, account);
}
return account;
}
@ -183,7 +176,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
if(UUID.TryParse(id, out uuid))
{
lock(m_Cache)
account = m_Cache.Get(uuid, out inCache);
if (inCache)
accs.Add(account);
@ -202,7 +194,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
if(acc != null)
{
accs.Add(acc);
lock(m_Cache)
m_Cache.Cache(acc.PrincipalID, acc);
}
}

View File

@ -44,6 +44,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
private ExpiringCache<UUID, UserAccount> m_UUIDCache;
private ExpiringCache<string, UUID> m_NameCache;
private object accessLock = new object();
public UserAccountCache()
{
@ -54,15 +55,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
public void Cache(UUID userID, UserAccount account)
{
// Cache even null accounts
lock(accessLock)
{
m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
if (account != null)
m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
//m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
}
}
public void Invalidate(UUID userID)
{
lock(accessLock)
m_UUIDCache.Remove(userID);
}
@ -70,35 +75,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
UserAccount account = null;
inCache = false;
lock(accessLock)
{
if (m_UUIDCache.TryGetValue(userID, out account))
{
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
inCache = true;
return account;
}
}
return null;
}
public UserAccount Get(string name, out bool inCache)
{
inCache = false;
lock(accessLock)
{
if (!m_NameCache.Contains(name))
return null;
UserAccount account = null;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
{
if (m_UUIDCache.TryGetValue(uuid, out account))
{
inCache = true;
return account;
}
}
}
return null;
}
public void Remove(string name)
{
lock(accessLock)
{
if (!m_NameCache.Contains(name))
return;
@ -111,4 +124,5 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
}
}
}
}
}