Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data


< > BotCompany Repo | #1005146 - getServerTranspiled2 - with (safe) caching

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4667L/31K).

scope getServerTranspiled2.

please include function loadPage.

sbool #allowLocalFallback = true, #localFallbackVerbose = true;

// to avoid checking server for transpilations too often when booting OS
static SS getServerTranspiled2_tempCache;

sS getServerTranspiled2(S id) {
  ifndef NoResourceLoader
  IResourceLoader rl = vm_getResourceLoader();
  if (rl != null)
    ret rl.getTranspiled(id);
  ret getServerTranspiled2_noResourceLoader(id);
sS getServerTranspiled2_noResourceLoader(S id) {
  id = fsIOpt(id);
  S transpiled = mapGet(getServerTranspiled2_tempCache, id);
  if (transpiled != null) ret transpiled;
  //if (getServerTranspiled2_tempCache != null) print("CACHE FAIL on " + id);
  transpiled = loadCachedTranspilation(id);
  S md5 = null;
  if (machineIsOffline() || isOfflineMode() || isLocalSnippet(id)) ret transpiled;
  if (transpiled != null)
    md5 = md5(transpiled);
  S transpiledSrc;
  try {
    transpiledSrc = getServerTranspiled(formatSnippetID(id), md5);
  } catch e {
    if (!allowLocalFallback) rethrow(e);
    if (localFallbackVerbose) print("Fallback to local code");
    ret transpiled;
  if (eq(transpiledSrc, "SAME")) {
    if (!isTrue(loadPage_silent!)) print("SAME");
    ret mapPut_returnValue(getServerTranspiled2_tempCache, id, transpiled);
  ret mapPut_returnValue(getServerTranspiled2_tempCache, id, transpiledSrc);

end scope

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005146
Snippet name: getServerTranspiled2 - with (safe) caching
Eternal ID of this version: #1005146/16
Text MD5: 3a1ff979fae1e9d6425041f5a452cf32
Transpilation MD5: 86ff74efc7ce481054e861475f6348be
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-14 14:38:42
Source code size: 1483 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 496 / 721
Version history: 15 change(s)
Referenced in: [show references]

Formerly at &