@Override public Datastore.Stats getStats(boolean useCache) { if (useCache) { try { Stats cachedStats = (Stats) STATS_CACHE.get(STATS_CACHE_KEY); if (cachedStats != null) { return cachedStats; } logger.info("Stats not in cache, re-computing"); } catch (InvalidValueException err) { logger.log(Level.WARNING, "Could not load data from memcache", err); } } Stats ret = new Stats(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(new com.google.appengine.api.datastore.Query("__Stat_Kind__")); for (Entity kindStat : pq.asIterable()) { String kind = (String) kindStat.getProperty("kind_name"); if ("Channel".equals(kind)) { ret.numChannels = ((Long) kindStat.getProperty("count")).intValue(); ret.timestamp = (Date) kindStat.getProperty("timestamp"); } } ret.numUsers = countUsersActiveInLastNDays(datastore, -1); ret.oneDayActiveUsers = countUsersActiveInLastNDays(datastore, 1); ret.sevenDayActiveUsers = countUsersActiveInLastNDays(datastore, 7); ret.thirtyDayActiveUsers = countUsersActiveInLastNDays(datastore, 30); STATS_CACHE.put(STATS_CACHE_KEY, ret); return ret; }