diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/HypergridService/UserAccountCache.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs new file mode 100644 index 0000000..3e9aea1 --- /dev/null +++ b/OpenSim/Services/HypergridService/UserAccountCache.cs | |||
@@ -0,0 +1,105 @@ | |||
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 | private ExpiringCache<UUID, UserAccount> m_UUIDCache; | ||
20 | |||
21 | private IUserAccountService m_UserAccountService; | ||
22 | |||
23 | private static UserAccountCache m_Singleton; | ||
24 | |||
25 | public static UserAccountCache CreateUserAccountCache(IUserAccountService u) | ||
26 | { | ||
27 | if (m_Singleton == null) | ||
28 | m_Singleton = new UserAccountCache(u); | ||
29 | |||
30 | return m_Singleton; | ||
31 | } | ||
32 | |||
33 | private UserAccountCache(IUserAccountService u) | ||
34 | { | ||
35 | m_UUIDCache = new ExpiringCache<UUID, UserAccount>(); | ||
36 | m_UserAccountService = u; | ||
37 | } | ||
38 | |||
39 | public void Cache(UUID userID, UserAccount account) | ||
40 | { | ||
41 | // Cache even null accounts | ||
42 | m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); | ||
43 | |||
44 | //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); | ||
45 | } | ||
46 | |||
47 | public UserAccount Get(UUID userID, out bool inCache) | ||
48 | { | ||
49 | UserAccount account = null; | ||
50 | inCache = false; | ||
51 | if (m_UUIDCache.TryGetValue(userID, out account)) | ||
52 | { | ||
53 | //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); | ||
54 | inCache = true; | ||
55 | return account; | ||
56 | } | ||
57 | |||
58 | return null; | ||
59 | } | ||
60 | |||
61 | public UserAccount GetUser(string id) | ||
62 | { | ||
63 | UUID uuid = UUID.Zero; | ||
64 | UUID.TryParse(id, out uuid); | ||
65 | bool inCache = false; | ||
66 | UserAccount account = Get(uuid, out inCache); | ||
67 | if (!inCache) | ||
68 | { | ||
69 | account = m_UserAccountService.GetUserAccount(UUID.Zero, uuid); | ||
70 | Cache(uuid, account); | ||
71 | } | ||
72 | |||
73 | return account; | ||
74 | } | ||
75 | |||
76 | #region IUserAccountService | ||
77 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
78 | { | ||
79 | return GetUser(userID.ToString()); | ||
80 | } | ||
81 | |||
82 | public UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName) | ||
83 | { | ||
84 | return null; | ||
85 | } | ||
86 | |||
87 | public UserAccount GetUserAccount(UUID scopeID, string Email) | ||
88 | { | ||
89 | return null; | ||
90 | } | ||
91 | |||
92 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
93 | { | ||
94 | return null; | ||
95 | } | ||
96 | |||
97 | public bool StoreUserAccount(UserAccount data) | ||
98 | { | ||
99 | return false; | ||
100 | } | ||
101 | #endregion | ||
102 | |||
103 | } | ||
104 | |||
105 | } | ||