Browse Source

Edited loadLanguage to no longer overwrite cache with data from cache per #666

dev/v4
Balearica 2 years ago
parent
commit
c0298ff1fa
  1. 4
      src/worker-script/index.js

4
src/worker-script/index.js

@ -82,6 +82,7 @@ res) => { @@ -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) => { @@ -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) => { @@ -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);
}

Loading…
Cancel
Save