--- android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/09/21 16:45:24 1092 +++ android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/09/21 20:10:46 1093 @@ -4,14 +4,21 @@ import java.net.URL; import java.sql.SQLException; +import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import net.sf.jsr107cache.Cache; +import net.sf.jsr107cache.CacheException; +import net.sf.jsr107cache.CacheManager; + import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import com.google.appengine.api.memcache.jsr107cache.GCacheFactory; + import dk.thoerup.android.traininfo.common.TimetableBean; import dk.thoerup.android.traininfo.common.TimetableEntry; import dk.thoerup.circuitbreaker.CircuitBreaker; @@ -22,8 +29,8 @@ public class TimetableFetcher { - Map cache; - Map stationCache; + Cache cache; + Cache stationCache; StationDAO stationDao = new StationDAO(); @@ -33,12 +40,28 @@ private boolean useAzureSite; private int replyTimeout; + @SuppressWarnings("unchecked") public TimetableFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) { useAzureSite = azureSite; - this.replyTimeout = replyTimeout; + this.replyTimeout = replyTimeout; + + Map props = new HashMap(); + props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, cacheTimeout); + + try { + cache = CacheManager.getInstance().getCacheFactory().createCache(props); + } catch (CacheException e) { + logger.log(Level.WARNING, "error creating cache", e); + } + + props = new HashMap(); + props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, 3*60*60*1000); - cache = new TimeoutMap(cacheTimeout); - stationCache = new TimeoutMap( 3*60*60*1000 ); + try { + stationCache = CacheManager.getInstance().getCacheFactory().createCache(props); + } catch (CacheException e) { + logger.log(Level.WARNING, "error creating cache", e); + } }