Fixed caching of user accounts.

slimupdates
Diva Canto 2010-03-09 17:09:44 -08:00
parent 88771aeed3
commit dbb2edf1a6
5 changed files with 45 additions and 32 deletions

View File

@ -142,26 +142,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
public UserAccount GetUserAccount(UUID scopeID, UUID userID)
{
UserAccount account = m_Cache.Get(userID);
if (account != null)
bool inCache = false;
UserAccount account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = m_UserService.GetUserAccount(scopeID, userID);
if (account != null)
m_Cache.Cache(account);
m_Cache.Cache(userID, account);
return account;
}
public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
{
UserAccount account = m_Cache.Get(firstName + " " + lastName);
if (account != null)
bool inCache = false;
UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = m_UserService.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
m_Cache.Cache(account);
m_Cache.Cache(account.PrincipalID, account);
return account;
}

View File

@ -119,26 +119,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
{
UserAccount account = m_Cache.Get(userID);
if (account != null)
bool inCache = false;
UserAccount account = m_Cache.Get(userID, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, userID);
if (account != null)
m_Cache.Cache(account);
m_Cache.Cache(userID, account);
return account;
}
public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
{
UserAccount account = m_Cache.Get(firstName + " " + lastName);
if (account != null)
bool inCache = false;
UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
if (inCache)
return account;
account = base.GetUserAccount(scopeID, firstName, lastName);
if (account != null)
m_Cache.Cache(account);
m_Cache.Cache(account.PrincipalID, account);
return account;
}

View File

@ -36,50 +36,58 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
public class UserAccountCache
{
//private static readonly ILog m_log =
// LogManager.GetLogger(
// MethodBase.GetCurrentMethod().DeclaringType);
private ICnmCache<UUID, UserAccount> m_UUIDCache;
private Dictionary<string, UUID> m_NameCache;
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private ExpiringCache<UUID, UserAccount> m_UUIDCache;
private ExpiringCache<string, UUID> m_NameCache;
public UserAccountCache()
{
// Warning: the size values are a bit fuzzy. What matters
// most for this cache is the count value (128 entries).
m_UUIDCache = CnmSynchronizedCache<UUID, UserAccount>.Synchronized(new CnmMemoryCache<UUID, UserAccount>(
128, 128*512, TimeSpan.FromMinutes(30.0)));
m_NameCache = new Dictionary<string, UUID>(); // this one is unbound
m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
m_NameCache = new ExpiringCache<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);
m_NameCache[account.Name] = account.PrincipalID;
// Cache even null accounts
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;
inCache = false;
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)
public UserAccount Get(string name, out bool inCache)
{
if (!m_NameCache.ContainsKey(name))
inCache = false;
if (!m_NameCache.Contains(name))
return null;
UserAccount account = null;
if (m_UUIDCache.TryGetValue(m_NameCache[name], out account))
return account;
UUID uuid = UUID.Zero;
if (m_NameCache.TryGetValue(name, out uuid))
if (m_UUIDCache.TryGetValue(uuid, out account))
{
inCache = true;
return account;
}
return null;
}

View File

@ -113,6 +113,7 @@ namespace OpenSim.Services.Connectors
public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID)
{
m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUSerAccount {0}", userID);
Dictionary<string, object> sendData = new Dictionary<string, object>();
//sendData["SCOPEID"] = scopeID.ToString();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();

View File

@ -200,7 +200,9 @@ namespace OpenSim.Services.UserAccountService
}
if (d.Length < 1)
{
return null;
}
return MakeUserAccount(d[0]);
}