--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2009/10/02 13:44:31 386 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2009/10/07 13:37:37 410 @@ -8,7 +8,7 @@ import java.util.List; import java.util.logging.Logger; -import com.gargoylesoftware.htmlunit.ProxyConfig; + import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.DomNodeList; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -19,6 +19,23 @@ public class DepartureFetcher { Logger logger = Logger.getLogger(DepartureFetcher.class.getName()); + + TimeoutCache> cache = new TimeoutCache>(120 * 1000); + + + + public List cachedLookupDepartures(int stationID) throws Exception { + + List list = cache.get(stationID); + + if (list == null) { + list = lookupDepartures(stationID); + cache.put(stationID, list); + } else { + logger.info("Departure: Cache hit " + stationID); //remove before production + } + return list; + } public List lookupDepartures(int stationID) throws Exception { @@ -90,7 +107,7 @@ departure.setUpdated(updated); String trainNumber = fields.get(2).asText(); - if (trainNumber.trim().length() == 1) + if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); departure.setTrainNumber(trainNumber);