diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/HypergridService/UserAccountCache.cs | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/HypergridService/UserAccountCache.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/UserAccountCache.cs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs new file mode 100644 index 0000000..fa7dd0b --- /dev/null +++ b/OpenSim/Services/HypergridService/UserAccountCache.cs | |||
@@ -0,0 +1,111 @@ | |||
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 void InvalidateCache(UUID userID) | ||
99 | { | ||
100 | m_UUIDCache.Remove(userID); | ||
101 | } | ||
102 | |||
103 | public bool StoreUserAccount(UserAccount data) | ||
104 | { | ||
105 | return false; | ||
106 | } | ||
107 | #endregion | ||
108 | |||
109 | } | ||
110 | |||
111 | } | ||