OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
UserAccountCache.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Reflection;
4 
5 using log4net;
6 using OpenMetaverse;
7 
8 using OpenSim.Services.Interfaces;
9 
10 namespace OpenSim.Services.HypergridService
11 {
13  {
14  private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours!
15 
16 // private static readonly ILog m_log =
17 // LogManager.GetLogger(
18 // MethodBase.GetCurrentMethod().DeclaringType);
19 
20  private ExpiringCache<UUID, UserAccount> m_UUIDCache;
21 
22  private IUserAccountService m_UserAccountService;
23 
24  private static UserAccountCache m_Singleton;
25 
27  {
28  if (m_Singleton == null)
29  m_Singleton = new UserAccountCache(u);
30 
31  return m_Singleton;
32  }
33 
35  {
36  m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
37  m_UserAccountService = u;
38  }
39 
40  public void Cache(UUID userID, UserAccount account)
41  {
42  // Cache even null accounts
43  m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
44 
45  //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
46  }
47 
48  public UserAccount Get(UUID userID, out bool inCache)
49  {
50  UserAccount account = null;
51  inCache = false;
52  if (m_UUIDCache.TryGetValue(userID, out account))
53  {
54  //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
55  inCache = true;
56  return account;
57  }
58 
59  return null;
60  }
61 
62  public UserAccount GetUser(string id)
63  {
64  UUID uuid = UUID.Zero;
65  UUID.TryParse(id, out uuid);
66  bool inCache = false;
67  UserAccount account = Get(uuid, out inCache);
68  if (!inCache)
69  {
70  account = m_UserAccountService.GetUserAccount(UUID.Zero, uuid);
71  Cache(uuid, account);
72  }
73 
74  return account;
75  }
76 
77  #region IUserAccountService
78  public UserAccount GetUserAccount(UUID scopeID, UUID userID)
79  {
80  return GetUser(userID.ToString());
81  }
82 
83  public UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName)
84  {
85  return null;
86  }
87 
88  public UserAccount GetUserAccount(UUID scopeID, string Email)
89  {
90  return null;
91  }
92 
93  public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
94  {
95  return null;
96  }
97 
98  public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
99  {
100  return null;
101  }
102 
103  public void InvalidateCache(UUID userID)
104  {
105  m_UUIDCache.Remove(userID);
106  }
107 
108  public bool StoreUserAccount(UserAccount data)
109  {
110  return false;
111  }
112  #endregion
113 
114  }
115 
116 }
List< UserAccount > GetUserAccounts(UUID scopeID, string query)
Returns the list of avatars that matches both the search criterion and the scope ID passed ...
List< UserAccount > GetUserAccountsWhere(UUID scopeID, string query)
void Cache(UUID userID, UserAccount account)
static UserAccountCache CreateUserAccountCache(IUserAccountService u)
UserAccount GetUserAccount(UUID scopeID, UUID userID)
UserAccount GetUserAccount(UUID scopeID, string Email)
UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName)
UserAccount Get(UUID userID, out bool inCache)
bool StoreUserAccount(UserAccount data)
Store the data given, wich replaces the stored data, therefore must be complete.