// Logic: Checks every 10 seconds and clears full cache when // anything changed in the DB. So it's as good as traffic-free // when the DB is not changing. !752 static int updateInterval = 10000; static long lastVersionCount; static new Map md5s; p { startBot("Version Count Bot", "#1001745"); makeBot("Transpilation MD5 Bot."); updateLoop(); } static void update() { new Matches m; if (match("version count: *", sendToLocalBot_cached("Version Count Bot", "get version count"), m)) { long count = parseLong(m.get(0)); if (count != lastVersionCount) { lastVersionCount = count; clear(); } } } static synchronized S answer(S s) { new Matches m; // current = get transpilation md5 only if transpilation is up to date if (match3("what is the current transpilation md5 of snippet *", s, m)) { S snippetID = formatSnippetID(m.unq(0)); S md5 = md5s.get(snippetID); if (md5 == null) { md5 = getCurrentTranspilationMD5(snippetID); if (md5 == null) ret "null"; md5s.put(snippetID, md5); } if (isMD5(md5)) ret format("The current transpilation md5 of snippet * is *.", snippetID, md5); else ret "Transpilation is out of date."; } if (match3("clear snippet md5 cache", s, m)) { clear(); ret "OK."; } if (match3("get snippet md5 cache size", s, m)) { ret "Cache entries: " + md5s.size(); } ret null; } static synchronized void clear() { md5s.clear(); } static S getCurrentTranspilationMD5(S snippetID) { S s = loadPage("http://tinybrain.de:8080/tb-int/get-transpilation-md5.php?id=" + parseSnippetID(snippetID)).trim(); ret s; }