// only works within a module // has mild race conditions sclass SnippetInstaCache is AutoCloseable { // snippet ID to text SS texts = syncMap(); AutoCloseable updater; *(S... snippetIDs) { this(asList(snippetIDs)); } *(Iterable snippetIDs) { updater = dm_onSnippetEdited(voidfunc(S id) { bool contained = texts.containsKey(id); print("SnippetInstaCache: snippet edited " + id + ", contained: " + contained); if (contained) texts.put(id, loadSnippet(id)); }); fOr (snippetID : map fsI(snippetIDs)) texts.put(snippetID, loadSnippet(snippetID)); } // get snippet text S get(S snippetID) { ret texts.get(fsI(snippetID)); } close { dispose updater; } Cl cachedSnippetIDs() { ret cloneKeys(texts); } }