summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/LectureCache.java
blob: b20acbefd6acd807a4dace4a683f1a2325f565ec (plain) (tree)
1
2
3
4
5
6
7
8
9
                                        





                                                             
                                                          
                                         





                                                   
                                                                


                                                                                                                                                
                                                                                                                          
                                                           
                                                                             


















                                                                                                                                        
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.TInvocationException;
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 = 30 * 1000;

	private static final GenericDataCache<List<LectureSummary>> listCache = new GenericDataCache<List<LectureSummary>>(CACHE_TIME_LIST_MS) {
		@Override
		protected List<LectureSummary> update() throws TAuthorizationException, TInvocationException, 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);
	}

}