blob: eb80b61ea97f5267b3cdf572f9d6b379446578f8 (
plain) (
tree)
|
|
package org.openslx.dozmod.thrift;
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.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 = ThriftManager.getSatClient().getPageSize();
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);
}
}
|