Migrate to Cache for commonly used data

Previously it was abusing the `localStorage` and now it is storing data in memory (per session).
This commit is contained in:
Chocobo1
2024-02-10 15:26:16 +08:00
parent d06d5b923a
commit 963a7faab8
4 changed files with 73 additions and 54 deletions

View File

@@ -34,10 +34,33 @@ if (window.qBittorrent === undefined)
window.qBittorrent.Cache = (() => {
const exports = () => {
return {
preferences: new PreferencesCache()
buildInfo: new BuildInfoCache(),
preferences: new PreferencesCache(),
qbtVersion: new QbtVersionCache()
};
};
class BuildInfoCache {
#m_store = {};
init() {
new Request.JSON({
url: 'api/v2/app/buildInfo',
method: 'get',
noCache: true,
onSuccess: (responseJSON) => {
if (!responseJSON)
return;
this.#m_store = responseJSON;
}
}).send();
}
get() {
return structuredClone(this.#m_store);
}
}
class PreferencesCache {
#m_store = {};
@@ -106,6 +129,27 @@ window.qBittorrent.Cache = (() => {
}
}
class QbtVersionCache {
#m_store = '';
init() {
new Request({
url: 'api/v2/app/version',
method: 'get',
noCache: true,
onSuccess: (responseText) => {
if (!responseText)
return;
this.#m_store = responseText;
}
}).send();
}
get() {
return this.#m_store;
}
}
return exports();
})();