--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2009/10/02 13:44:31 386 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2009/10/02 15:06:08 387 @@ -7,8 +7,12 @@ import java.util.List; import java.util.logging.Logger; -import com.gargoylesoftware.htmlunit.*; -import com.gargoylesoftware.htmlunit.html.*; +import com.gargoylesoftware.htmlunit.Page; +import com.gargoylesoftware.htmlunit.RefreshHandler; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.DomNodeList; +import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlPage; public class TimetableFetcher { @@ -17,10 +21,28 @@ } } + + TimeoutCache> cache = new TimeoutCache>(120 * 1000); + Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); + + + List cachedLookupTimetable(String trainID, String type) throws Exception { + String key = trainID+type; + List list = cache.get(key); + + if (list == null) { + logger.warning("Timetable: Cache miss " + trainID); //remove before production + list = lookupTimetable(trainID,type); + cache.put(key, list); + } else { + logger.warning("Timetable: Cache hit " + trainID); //remove before production + } + return list; + } - List lookupTimetable(String trainID, String type) throws Exception { + List lookupTimetable(String trainID, String type) throws Exception { List timetableList = new ArrayList(); String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276";