From c0298ff1fa617242aa769fbf15beb9bbad11e011 Mon Sep 17 00:00:00 2001 From: Balearica Date: Mon, 19 Sep 2022 19:15:17 -0700 Subject: [PATCH] Edited loadLanguage to no longer overwrite cache with data from cache per #666 --- src/worker-script/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/worker-script/index.js b/src/worker-script/index.js index 1ca0744..1153a06 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -82,6 +82,7 @@ res) => { ? () => Promise.resolve() : adapter.readCache; let data = null; + let newData = false; try { const _data = await readCache(`${cachePath || '.'}/${lang}.traineddata`); @@ -93,6 +94,7 @@ res) => { throw Error('Not found in cache'); } } catch (e) { + newData = true; log(`[${workerId}]: Load ${lang}.traineddata from ${langPath}`); if (typeof _lang === 'string') { let path = null; @@ -134,7 +136,7 @@ res) => { TessModule.FS.writeFile(`${dataPath || '.'}/${lang}.traineddata`, data); } - if (['write', 'refresh', undefined].includes(cacheMethod)) { + if (newData && ['write', 'refresh', undefined].includes(cacheMethod)) { await adapter.writeCache(`${cachePath || '.'}/${lang}.traineddata`, data); }