--- android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/04/23 15:28:34 666 +++ android/MarketStats/src/dk/thoerup/marketstats/ShowStats.java 2010/04/26 07:57:45 669 @@ -30,6 +30,8 @@ String login; String password; + + MemcachedClient memcache = null; @Override @@ -38,18 +40,23 @@ login = getServletContext().getInitParameter("login"); password = getServletContext().getInitParameter("password"); + + try { + memcache = new MemcachedClient(new InetSocketAddress("localhost", 11211)); + } catch (IOException e) { + throw new ServletException(e); + } } protected String doLookup(String appId) throws IOException { - MemcachedClient c = new MemcachedClient(new InetSocketAddress("localhost", 11211)); - + String key = "marketstats:" + appId; - String response = (String) c.get(key); + String response = (String) memcache.get(key); if (response == null) { response = doLookupWorker(appId); - c.set(key, TIMEOUT, response); + memcache.set(key, TIMEOUT, response); response += ""; } else { response += ""; @@ -128,7 +135,8 @@ sb.append("\n"); } - sb.append("Comments: " + commentBeans.size() ); + sb.append("Comments: " + commentBeans.size() + "\n"); + sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes"); return sb.toString();