Disable cache on the backend and fix a bug with the cache key
This commit is contained in:
parent
823c026533
commit
e1ebfb02f7
@ -53,7 +53,8 @@ class Backend {
|
|||||||
this.defaultAnkiFieldTemplates = null;
|
this.defaultAnkiFieldTemplates = null;
|
||||||
this.audioUriBuilder = new AudioUriBuilder();
|
this.audioUriBuilder = new AudioUriBuilder();
|
||||||
this.audioSystem = new AudioSystem({
|
this.audioSystem = new AudioSystem({
|
||||||
audioUriBuilder: this.audioUriBuilder
|
audioUriBuilder: this.audioUriBuilder,
|
||||||
|
useCache: false
|
||||||
});
|
});
|
||||||
this.ankiNoteBuilder = new AnkiNoteBuilder({
|
this.ankiNoteBuilder = new AnkiNoteBuilder({
|
||||||
anki: this.anki,
|
anki: this.anki,
|
||||||
|
@ -28,7 +28,10 @@ let audioSourceUI = null;
|
|||||||
let audioSystem = null;
|
let audioSystem = null;
|
||||||
|
|
||||||
async function audioSettingsInitialize() {
|
async function audioSettingsInitialize() {
|
||||||
audioSystem = new AudioSystem({audioUriBuilder: null});
|
audioSystem = new AudioSystem({
|
||||||
|
audioUriBuilder: null,
|
||||||
|
useCache: true
|
||||||
|
});
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await getOptionsMutable(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
|
@ -66,8 +66,8 @@ class TextToSpeechAudio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AudioSystem {
|
class AudioSystem {
|
||||||
constructor({audioUriBuilder}) {
|
constructor({audioUriBuilder, useCache}) {
|
||||||
this._cache = new Map();
|
this._cache = useCache ? new Map() : null;
|
||||||
this._cacheSizeMaximum = 32;
|
this._cacheSizeMaximum = 32;
|
||||||
this._audioUriBuilder = audioUriBuilder;
|
this._audioUriBuilder = audioUriBuilder;
|
||||||
|
|
||||||
@ -79,10 +79,14 @@ class AudioSystem {
|
|||||||
|
|
||||||
async getDefinitionAudio(definition, sources, details) {
|
async getDefinitionAudio(definition, sources, details) {
|
||||||
const key = `${definition.expression}:${definition.reading}`;
|
const key = `${definition.expression}:${definition.reading}`;
|
||||||
const cacheValue = this._cache.get(definition);
|
const hasCache = (this._cache !== null);
|
||||||
if (typeof cacheValue !== 'undefined') {
|
|
||||||
const {audio, uri, source} = cacheValue;
|
if (hasCache) {
|
||||||
return {audio, uri, source};
|
const cacheValue = this._cache.get(key);
|
||||||
|
if (typeof cacheValue !== 'undefined') {
|
||||||
|
const {audio, uri, source} = cacheValue;
|
||||||
|
return {audio, uri, source};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const source of sources) {
|
for (const source of sources) {
|
||||||
@ -91,8 +95,10 @@ class AudioSystem {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const audio = await this._createAudio(uri);
|
const audio = await this._createAudio(uri);
|
||||||
this._cacheCheck();
|
if (hasCache) {
|
||||||
this._cache.set(key, {audio, uri, source});
|
this._cacheCheck();
|
||||||
|
this._cache.set(key, {audio, uri, source});
|
||||||
|
}
|
||||||
return {audio, uri, source};
|
return {audio, uri, source};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
|
@ -50,7 +50,8 @@ class Display {
|
|||||||
async getUri(definition, source, details) {
|
async getUri(definition, source, details) {
|
||||||
return await apiAudioGetUri(definition, source, details);
|
return await apiAudioGetUri(definition, source, details);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
useCache: true
|
||||||
});
|
});
|
||||||
this.styleNode = null;
|
this.styleNode = null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user