Disable cache on the backend and fix a bug with the cache key

This commit is contained in:
toasted-nutbread 2020-04-10 16:12:55 -04:00
parent 823c026533
commit e1ebfb02f7
4 changed files with 22 additions and 11 deletions

View File

@ -53,7 +53,8 @@ class Backend {
this.defaultAnkiFieldTemplates = null;
this.audioUriBuilder = new AudioUriBuilder();
this.audioSystem = new AudioSystem({
audioUriBuilder: this.audioUriBuilder
audioUriBuilder: this.audioUriBuilder,
useCache: false
});
this.ankiNoteBuilder = new AnkiNoteBuilder({
anki: this.anki,

View File

@ -28,7 +28,10 @@ let audioSourceUI = null;
let audioSystem = null;
async function audioSettingsInitialize() {
audioSystem = new AudioSystem({audioUriBuilder: null});
audioSystem = new AudioSystem({
audioUriBuilder: null,
useCache: true
});
const optionsContext = getOptionsContext();
const options = await getOptionsMutable(optionsContext);

View File

@ -66,8 +66,8 @@ class TextToSpeechAudio {
}
class AudioSystem {
constructor({audioUriBuilder}) {
this._cache = new Map();
constructor({audioUriBuilder, useCache}) {
this._cache = useCache ? new Map() : null;
this._cacheSizeMaximum = 32;
this._audioUriBuilder = audioUriBuilder;
@ -79,10 +79,14 @@ class AudioSystem {
async getDefinitionAudio(definition, sources, details) {
const key = `${definition.expression}:${definition.reading}`;
const cacheValue = this._cache.get(definition);
if (typeof cacheValue !== 'undefined') {
const {audio, uri, source} = cacheValue;
return {audio, uri, source};
const hasCache = (this._cache !== null);
if (hasCache) {
const cacheValue = this._cache.get(key);
if (typeof cacheValue !== 'undefined') {
const {audio, uri, source} = cacheValue;
return {audio, uri, source};
}
}
for (const source of sources) {
@ -91,8 +95,10 @@ class AudioSystem {
try {
const audio = await this._createAudio(uri);
this._cacheCheck();
this._cache.set(key, {audio, uri, source});
if (hasCache) {
this._cacheCheck();
this._cache.set(key, {audio, uri, source});
}
return {audio, uri, source};
} catch (e) {
// NOP

View File

@ -50,7 +50,8 @@ class Display {
async getUri(definition, source, details) {
return await apiAudioGetUri(definition, source, details);
}
}
},
useCache: true
});
this.styleNode = null;