Skip to content

Commit

Permalink
refactor(Options): separate default settings for make cache (#6330)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckohen committed Aug 7, 2021
1 parent 68c0591 commit d14a6bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
48 changes: 33 additions & 15 deletions src/util/Options.js
Expand Up @@ -102,21 +102,7 @@ class Options extends null {
static createDefault() {
return {
shardCount: 1,
makeCache: this.cacheWithLimits({
MessageManager: 200,
ChannelManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
GuildChannelManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
ThreadManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
}),
makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings),
messageCacheLifetime: 0,
messageSweepInterval: 0,
invalidRequestWarningInterval: 0,
Expand Down Expand Up @@ -173,6 +159,9 @@ class Options extends null {
* @example
* // Sweep messages every 5 minutes, removing messages that have not been edited or created in the last 30 minutes
* Options.cacheWithLimits({
* // Keep default thread sweeping behavior
* ...Options.defaultMakeCacheSettings,
* // Override MessageManager
* MessageManager: {
* sweepInterval: 300,
* sweepFilter: LimitedCollection.filterByLifetime({
Expand Down Expand Up @@ -221,6 +210,35 @@ class Options extends null {
const { Collection } = require('@discordjs/collection');
return () => new Collection();
}

/**
* The default settings passed to {@link Options.cacheWithLimits}.
* The caches that this changes are:
* * `MessageManager` - Limit to 200 messages
* * `ChannelManager` - Sweep archived threads
* * `GuildChannelManager` - Sweep archived threads
* * `ThreadManager` - Sweep archived threads
* <info>If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g.
* `makeCache: Options.cacheWithLimits({ ...Options.defaultmakeCacheSettings, ReactionManager: 0 })`</info>
* @type {Object<string, LimitedCollectionOptions|number>}
*/
static get defaultMakeCacheSettings() {
return {
MessageManager: 200,
ChannelManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
GuildChannelManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
ThreadManager: {
sweepInterval: 3600,
sweepFilter: require('./Util').archivedThreadSweepFilter(),
},
};
}
}

module.exports = Options;
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -449,6 +449,7 @@ export class ClientUser extends User {

export class Options extends null {
private constructor();
public static defaultMakeCacheSettings: CacheWithLimitsOptions;
public static createDefaultOptions(): ClientOptions;
public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory;
public static cacheEverything(): CacheFactory;
Expand Down

0 comments on commit d14a6bf

Please sign in to comment.