// 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) { if (texts.containsKey(id)) texts.put(id, loadSnippet(id)); }); fOr (snippetID : map fsI(snippetIDs)) texts.put(snippetID, loadSnippet(snippetID); } S getSnippetText(S snippetID) { ret texts.get(fsI(snippetID)); } close { dispose updater; } }