// Logic: Checks every 5 minutes and clears full cache when // anything changed in the DB. So it's as good as traffic-free // when the DB is not changing. !7 static int updateInterval = 5*60000; static long lastVersionCount; static new Map titles; p { startBot("Version Count Bot", "#1001745"); makeAndroid3("Snippet Title Bot."); updateLoop(); } static void update() { new Matches m; if (match3("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; if (match3("what is the title of snippet *", s, m)) { S snippetID = formatSnippetID(m.unq(0)); S title = titles.get(snippetID); if (title == null) { title = getSnippetTitle(snippetID); if (title == null) ret "null"; titles.put(snippetID, title); } ret format("The title of snippet * is *.", snippetID, title); } if (match3("clear snippet title cache", s, m)) { clear(); ret "OK."; } if (match3("get snippet title cache size", s, m)) { ret "Cache entries: " + titles.size(); } ret null; } static synchronized void clear() { titles.clear(); }