opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | { |
||
12 | public class UserAccountCache : IUserAccountService |
||
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 | |||
26 | public static UserAccountCache CreateUserAccountCache(IUserAccountService u) |
||
27 | { |
||
28 | if (m_Singleton == null) |
||
29 | m_Singleton = new UserAccountCache(u); |
||
30 | |||
31 | return m_Singleton; |
||
32 | } |
||
33 | |||
34 | private UserAccountCache(IUserAccountService u) |
||
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> GetUserAccounts(UUID scopeID, string query) |
||
94 | { |
||
95 | return null; |
||
96 | } |
||
97 | |||
98 | public bool StoreUserAccount(UserAccount data) |
||
99 | { |
||
100 | return false; |
||
101 | } |
||
102 | #endregion |
||
103 | |||
104 | } |
||
105 | |||
106 | } |