summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-27 15:49:54 +0200
committerSimon Rettberg2015-08-27 15:49:54 +0200
commit951db6e8742a9abdc0a9420432c5825dcf428480 (patch)
tree57ceda25dba41f37f306dcdb2dff5573b5a0010a /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
parent[client] Fix comments in QFileChooser (diff)
downloadtutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.tar.gz
tutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.tar.xz
tutor-module-951db6e8742a9abdc0a9420432c5825dcf428480.zip
[client] More agressive cache usage for .get*byId .find in Thift Cache helpers
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java24
1 files changed, 19 insertions, 5 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
index d73f650d..fd23c376 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/UserCache.java
@@ -5,9 +5,11 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.dozmod.thrift.Session;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
public class UserCache {
@@ -63,12 +65,24 @@ public class UserCache {
* @return matching user, or <code>null</code> if not found
*/
public static UserInfo find(String userId) {
- List<UserInfo> list = cache.get();
- if (list == null)
+ // First, try in "always cached" mode
+ List<UserInfo> list = cache.get(CacheMode.ALWAYS_CACHED);
+ UserInfo user = find(userId, list);
+ if (user != null)
+ return user;
+ // Try again with a potential refresh
+ List<UserInfo> newList = cache.get(CacheMode.DEFAULT);
+ if (list == newList) // Returned list from cache as it was still recent enough
return null;
- for (UserInfo user : list) {
- if (user.userId.equals(userId))
- return user;
+ return find(userId, newList);
+ }
+
+ private static UserInfo find(String userId, List<UserInfo> list) {
+ if (list != null) {
+ for (UserInfo user : list) {
+ if (user.userId.equals(userId))
+ return user;
+ }
}
return null;
}