From 970bd325f1740bc38b9c0bd9dfc67938189c31d9 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+HerrEurobeat@users.noreply.github.com> Date: Mon, 26 Jun 2023 12:20:27 +0200 Subject: [PATCH 1/4] Add clearPicsCache() function to clear cache content --- components/apps.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/apps.js b/components/apps.js index 8acf06f2..1bf7bcae 100644 --- a/components/apps.js +++ b/components/apps.js @@ -567,6 +567,23 @@ class SteamUserApps extends SteamUserAppAuth { } } + /** + * Clears the current picsCache content. + * Make sure to disable 'changelistUpdateInterval' if the cache should not get repopulated. + */ + clearPicsCache() { + if (!this.options.enablePicsCache) { + throw new Error("PICS cache is not enabled."); + } + + // Reset cache back to default + this.picsCache = { + changenumber: 0, + apps: {}, + packages: {} + }; + } + /** * @protected */ From 3adef959802fd19d74b1116c4c1b66b8bf24625b Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+HerrEurobeat@users.noreply.github.com> Date: Mon, 26 Jun 2023 13:38:31 +0200 Subject: [PATCH 2/4] Save type of stored jobs --- components/03-messages.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/03-messages.js b/components/03-messages.js index 80022c26..25a5e2c7 100644 --- a/components/03-messages.js +++ b/components/03-messages.js @@ -438,6 +438,7 @@ class SteamUserMessages extends SteamUserConnection { if (callback) { jobIdSource = ++this._currentJobID; this._jobs[jobIdSource] = callback; + this._jobs[jobIdSource].type = emsg; // Save type of this job to be able to filter the object later on // Clean up old job callbacks after 2 minutes this._jobCleanupTimers.push(setTimeout(() => delete this._jobs[jobIdSource], 1000 * 60 * 2)); From f2827d6c2dcd3f9126c8a64483c46032e16363c0 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+HerrEurobeat@users.noreply.github.com> Date: Mon, 26 Jun 2023 13:51:08 +0200 Subject: [PATCH 3/4] Filter jobs object for PICS data for garbage collection --- components/apps.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/apps.js b/components/apps.js index 1bf7bcae..fd718bb2 100644 --- a/components/apps.js +++ b/components/apps.js @@ -582,6 +582,17 @@ class SteamUserApps extends SteamUserAppAuth { apps: {}, packages: {} }; + + // Filter jobs object for left over references to the old picsCache content so it will be garbage collected instantly + Object.keys(this._jobs).forEach((e) => { + let k = this._jobs[e]; + + if (k.type && [ EMsg.ClientPICSChangesSinceRequest, EMsg.ClientPICSProductInfoRequest, EMsg.ClientPICSAccessTokenRequest ].includes(k.type)) { + delete this._jobs[e]; + clearTimeout(this._jobCleanupTimers[e]); + delete this._jobCleanupTimers[e]; + } + }); } /** From 38180a2cb6e15a14a0f91db9a20ec018235e8710 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+HerrEurobeat@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:11:50 +0200 Subject: [PATCH 4/4] Add clearPicsCache() to documentation --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 33613527..4569ea9f 100644 --- a/README.md +++ b/README.md @@ -1059,6 +1059,15 @@ If `filter` is a boolean, it is interpreted as `excludeShared` for backward comp `ownsPackage(16018, true)` is the same as `ownsPackage(16018, {excludeShared: true})`. This usage is deprecated and will be removed in a future release. +### clearPicsCache() + +**v4.xx.x or later is required to use this method** + +Clears the content of the `picsCache` object and removes any associated jobs to free memory. +Make sure to disable [`changelistUpdateInterval`](#changelistUpdateInterval) if the cache should not get repopulated. + +`enablePicsCache` must be `true` to use this method. Otherwise, an `Error` will be thrown. + ### getStoreTagNames(language, tagIDs, callback) - `language` - The language you want tag names in, e.g. "english" or "spanish" - `tagIDs` - An array of one or more tag IDs