Fixed caching of user accounts.
parent
88771aeed3
commit
dbb2edf1a6
|
@ -142,26 +142,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
|
||||||
|
|
||||||
public UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
public UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
||||||
{
|
{
|
||||||
UserAccount account = m_Cache.Get(userID);
|
bool inCache = false;
|
||||||
if (account != null)
|
UserAccount account = m_Cache.Get(userID, out inCache);
|
||||||
|
if (inCache)
|
||||||
return account;
|
return account;
|
||||||
|
|
||||||
account = m_UserService.GetUserAccount(scopeID, userID);
|
account = m_UserService.GetUserAccount(scopeID, userID);
|
||||||
if (account != null)
|
m_Cache.Cache(userID, account);
|
||||||
m_Cache.Cache(account);
|
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
|
public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
|
||||||
{
|
{
|
||||||
UserAccount account = m_Cache.Get(firstName + " " + lastName);
|
bool inCache = false;
|
||||||
if (account != null)
|
UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
|
||||||
|
if (inCache)
|
||||||
return account;
|
return account;
|
||||||
|
|
||||||
account = m_UserService.GetUserAccount(scopeID, firstName, lastName);
|
account = m_UserService.GetUserAccount(scopeID, firstName, lastName);
|
||||||
if (account != null)
|
if (account != null)
|
||||||
m_Cache.Cache(account);
|
m_Cache.Cache(account.PrincipalID, account);
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,26 +119,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
|
||||||
|
|
||||||
public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
||||||
{
|
{
|
||||||
UserAccount account = m_Cache.Get(userID);
|
bool inCache = false;
|
||||||
if (account != null)
|
UserAccount account = m_Cache.Get(userID, out inCache);
|
||||||
|
if (inCache)
|
||||||
return account;
|
return account;
|
||||||
|
|
||||||
account = base.GetUserAccount(scopeID, userID);
|
account = base.GetUserAccount(scopeID, userID);
|
||||||
if (account != null)
|
m_Cache.Cache(userID, account);
|
||||||
m_Cache.Cache(account);
|
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
|
public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
|
||||||
{
|
{
|
||||||
UserAccount account = m_Cache.Get(firstName + " " + lastName);
|
bool inCache = false;
|
||||||
if (account != null)
|
UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
|
||||||
|
if (inCache)
|
||||||
return account;
|
return account;
|
||||||
|
|
||||||
account = base.GetUserAccount(scopeID, firstName, lastName);
|
account = base.GetUserAccount(scopeID, firstName, lastName);
|
||||||
if (account != null)
|
if (account != null)
|
||||||
m_Cache.Cache(account);
|
m_Cache.Cache(account.PrincipalID, account);
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,50 +36,58 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
|
||||||
{
|
{
|
||||||
public class UserAccountCache
|
public class UserAccountCache
|
||||||
{
|
{
|
||||||
//private static readonly ILog m_log =
|
private static readonly ILog m_log =
|
||||||
// LogManager.GetLogger(
|
LogManager.GetLogger(
|
||||||
// MethodBase.GetCurrentMethod().DeclaringType);
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
private ExpiringCache<UUID, UserAccount> m_UUIDCache;
|
||||||
private ICnmCache<UUID, UserAccount> m_UUIDCache;
|
private ExpiringCache<string, UUID> m_NameCache;
|
||||||
private Dictionary<string, UUID> m_NameCache;
|
|
||||||
|
|
||||||
public UserAccountCache()
|
public UserAccountCache()
|
||||||
{
|
{
|
||||||
// Warning: the size values are a bit fuzzy. What matters
|
// Warning: the size values are a bit fuzzy. What matters
|
||||||
// most for this cache is the count value (128 entries).
|
// most for this cache is the count value (128 entries).
|
||||||
m_UUIDCache = CnmSynchronizedCache<UUID, UserAccount>.Synchronized(new CnmMemoryCache<UUID, UserAccount>(
|
m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
|
||||||
128, 128*512, TimeSpan.FromMinutes(30.0)));
|
m_NameCache = new ExpiringCache<string, UUID>(); // this one is unbound
|
||||||
m_NameCache = new Dictionary<string, UUID>(); // this one is unbound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cache(UserAccount account)
|
public void Cache(UUID userID, UserAccount account)
|
||||||
{
|
{
|
||||||
m_UUIDCache.Set(account.PrincipalID, account, 512);
|
// Cache even null accounts
|
||||||
m_NameCache[account.Name] = account.PrincipalID;
|
m_UUIDCache.AddOrUpdate(userID, account, DateTime.Now + TimeSpan.FromMinutes(2.0d));
|
||||||
|
if (account != null)
|
||||||
|
m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, DateTime.Now + TimeSpan.FromMinutes(2.0d));
|
||||||
|
|
||||||
//m_log.DebugFormat("[USER CACHE]: cached user {0} {1}", account.FirstName, account.LastName);
|
m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAccount Get(UUID userID)
|
public UserAccount Get(UUID userID, out bool inCache)
|
||||||
{
|
{
|
||||||
UserAccount account = null;
|
UserAccount account = null;
|
||||||
|
inCache = false;
|
||||||
if (m_UUIDCache.TryGetValue(userID, out account))
|
if (m_UUIDCache.TryGetValue(userID, out account))
|
||||||
{
|
{
|
||||||
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
|
//m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
|
||||||
|
inCache = true;
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAccount Get(string name)
|
public UserAccount Get(string name, out bool inCache)
|
||||||
{
|
{
|
||||||
if (!m_NameCache.ContainsKey(name))
|
inCache = false;
|
||||||
|
if (!m_NameCache.Contains(name))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
UserAccount account = null;
|
UserAccount account = null;
|
||||||
if (m_UUIDCache.TryGetValue(m_NameCache[name], out account))
|
UUID uuid = UUID.Zero;
|
||||||
return account;
|
if (m_NameCache.TryGetValue(name, out uuid))
|
||||||
|
if (m_UUIDCache.TryGetValue(uuid, out account))
|
||||||
|
{
|
||||||
|
inCache = true;
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,7 @@ namespace OpenSim.Services.Connectors
|
||||||
|
|
||||||
public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
|
||||||
{
|
{
|
||||||
|
m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUSerAccount {0}", userID);
|
||||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||||
//sendData["SCOPEID"] = scopeID.ToString();
|
//sendData["SCOPEID"] = scopeID.ToString();
|
||||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||||
|
|
|
@ -200,7 +200,9 @@ namespace OpenSim.Services.UserAccountService
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.Length < 1)
|
if (d.Length < 1)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return MakeUserAccount(d[0]);
|
return MakeUserAccount(d[0]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue