summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-19 13:40:53 +0200
committerJonathan Bauer2015-08-19 13:40:53 +0200
commit5d94f0ba69a68a3fb733fc0617bc6a414dae8a52 (patch)
treea065cfe4e6d4ac593a8143e3c55e3624a02e0e54 /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java
parent[client] delete version through popupmenu with confirmation and refresh vers... (diff)
downloadtutor-module-5d94f0ba69a68a3fb733fc0617bc6a414dae8a52.tar.gz
tutor-module-5d94f0ba69a68a3fb733fc0617bc6a414dae8a52.tar.xz
tutor-module-5d94f0ba69a68a3fb733fc0617bc6a414dae8a52.zip
[client] move thrift cache to its own package
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java
new file mode 100644
index 00000000..6b4466c8
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java
@@ -0,0 +1,41 @@
+package org.openslx.dozmod.thrift.cache;
+
+import java.util.List;
+
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.LectureSummary;
+import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.TInternalServerError;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
+
+public class LectureCache {
+
+ private static final int CACHE_TIME_LIST_MS = 2 * 60 * 1000;
+
+ private static final GenericDataCache<List<LectureSummary>> listCache = new GenericDataCache<List<LectureSummary>>(CACHE_TIME_LIST_MS) {
+ @Override
+ protected List<LectureSummary> update() throws TAuthorizationException, TInternalServerError, TException {
+ List<LectureSummary> result = null;
+ int pageSize = Session.getSatelliteConfig().pageSize;
+ for (int i = 0;; ++i) {
+ List<LectureSummary> page = ThriftManager.getSatClient().getLectureList(Session.getSatelliteToken(), i);
+ if (result == null) {
+ result = page;
+ } else {
+ result.addAll(page);
+ }
+ if (page.size() < pageSize)
+ break;
+ }
+ return result;
+ }
+ };
+
+ public static List<LectureSummary> get(boolean forceRefresh) {
+ return listCache.get(forceRefresh ? CacheMode.NEVER_CACHED : CacheMode.DEFAULT);
+ }
+
+}