aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
diff options
context:
space:
mode:
authorDiva Canto2010-03-09 17:09:44 -0800
committerDiva Canto2010-03-09 17:09:44 -0800
commitdbb2edf1a67442b5e41da3cd8010574114bba7c2 (patch)
treeae277815d1f67bbbe3e1d3323ef53c4a5baf333f /OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
parentCache UserLevel in ScenePresence on SP creation. Change IsAdministrator (diff)
downloadopensim-SC_OLD-dbb2edf1a67442b5e41da3cd8010574114bba7c2.zip
opensim-SC_OLD-dbb2edf1a67442b5e41da3cd8010574114bba7c2.tar.gz
opensim-SC_OLD-dbb2edf1a67442b5e41da3cd8010574114bba7c2.tar.bz2
opensim-SC_OLD-dbb2edf1a67442b5e41da3cd8010574114bba7c2.tar.xz
Fixed caching of user accounts.
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs44
1 files changed, 26 insertions, 18 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
index e430fc7..a355661 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
@@ -36,50 +36,58 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
36{ 36{
37 public class UserAccountCache 37 public class UserAccountCache
38 { 38 {
39 //private static readonly ILog m_log = 39 private static readonly ILog m_log =
40 // LogManager.GetLogger( 40 LogManager.GetLogger(
41 // MethodBase.GetCurrentMethod().DeclaringType); 41 MethodBase.GetCurrentMethod().DeclaringType);
42 42 private ExpiringCache<UUID, UserAccount> m_UUIDCache;
43 private ICnmCache<UUID, UserAccount> m_UUIDCache; 43 private ExpiringCache<string, UUID> m_NameCache;
44 private Dictionary<string, UUID> m_NameCache;
45 44
46 public UserAccountCache() 45 public UserAccountCache()
47 { 46 {
48 // Warning: the size values are a bit fuzzy. What matters 47 // Warning: the size values are a bit fuzzy. What matters
49 // most for this cache is the count value (128 entries). 48 // most for this cache is the count value (128 entries).
50 m_UUIDCache = CnmSynchronizedCache<UUID, UserAccount>.Synchronized(new CnmMemoryCache<UUID, UserAccount>( 49 m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
51 128, 128*512, TimeSpan.FromMinutes(30.0))); 50 m_NameCache = new ExpiringCache<string, UUID>(); // this one is unbound
52 m_NameCache = new Dictionary<string, UUID>(); // this one is unbound
53 } 51 }
54 52
55 public void Cache(UserAccount account) 53 public void Cache(UUID userID, UserAccount account)
56 { 54 {
57 m_UUIDCache.Set(account.PrincipalID, account, 512); 55 // Cache even null accounts
58 m_NameCache[account.Name] = account.PrincipalID; 56 m_UUIDCache.AddOrUpdate(userID, account, DateTime.Now + TimeSpan.FromMinutes(2.0d));
57 if (account != null)
58 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, DateTime.Now + TimeSpan.FromMinutes(2.0d));
59 59
60 //m_log.DebugFormat("[USER CACHE]: cached user {0} {1}", account.FirstName, account.LastName); 60 m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
61 } 61 }
62 62
63 public UserAccount Get(UUID userID) 63 public UserAccount Get(UUID userID, out bool inCache)
64 { 64 {
65 UserAccount account = null; 65 UserAccount account = null;
66 inCache = false;
66 if (m_UUIDCache.TryGetValue(userID, out account)) 67 if (m_UUIDCache.TryGetValue(userID, out account))
67 { 68 {
68 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); 69 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
70 inCache = true;
69 return account; 71 return account;
70 } 72 }
71 73
72 return null; 74 return null;
73 } 75 }
74 76
75 public UserAccount Get(string name) 77 public UserAccount Get(string name, out bool inCache)
76 { 78 {
77 if (!m_NameCache.ContainsKey(name)) 79 inCache = false;
80 if (!m_NameCache.Contains(name))
78 return null; 81 return null;
79 82
80 UserAccount account = null; 83 UserAccount account = null;
81 if (m_UUIDCache.TryGetValue(m_NameCache[name], out account)) 84 UUID uuid = UUID.Zero;
82 return account; 85 if (m_NameCache.TryGetValue(name, out uuid))
86 if (m_UUIDCache.TryGetValue(uuid, out account))
87 {
88 inCache = true;
89 return account;
90 }
83 91
84 return null; 92 return null;
85 } 93 }