Skip to content

Commit

Permalink
docs!: improve descriptions for bulk removers
Browse files Browse the repository at this point in the history
  • Loading branch information
AwesomeStickz committed Oct 22, 2024
1 parent 5881cf6 commit ff87258
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ shouldCache: {

### `options.bulk`:

Lets you define how to deal with bulk removal of data. Useful to provide when you use cache outside memory. For example, if you store channels individually and separately from a guild, say in a database, when a guild is deleted, all of those channels will be deleted individually in individual queries, which is not ideal, so you can use `options.bulk.removeGuild` to delete the guild and all the channels related to that guild as one query or so, whichever gives better performance.
This option allows you to specify how to handle the removal of objects that may trigger bulk modifications or deletions of associated entities.

For example, if you store guild channels individually in a database separate from the guild itself, deleting a guild could result in each channel being deleted one by one through individual queries. This method can be inefficient, especially as the number of channels increases. To improve permformance, you can use `options.bulk.removeGuild` to remove the guild and all associated channels in a single query.

This provides the following props: (should be self explanatory with intellisense)

Expand All @@ -99,7 +101,7 @@ This provides the following props: (should be self explanatory with intellisense

### `options.sweeper`:

Lets you define options for sweeper. This works for in-memory cache only. For outside memory cache, you should implement your own sweeper.
This option allows you to specify options for sweeper. This works for in-memory cache only. For outside memory cache, you should implement your own sweeper.

This provides the following props:

Expand All @@ -108,11 +110,11 @@ This provides the following props:

#### `options.sweeper.interval`:

The interval (in milliseconds) in which the cache sweeper should run.
The interval (in milliseconds) at which the cache sweeper should run the provided filter functions.

#### `options.sweeper.filter`:

Lets you provide filter functions to decide which object to remove from cache and which to keep. Defaults to removing nothing from the cache, so you should provide your own filters if you enable cache sweeper.
This option allows you to provide filter functions to decide which object to remove from cache and which to keep. Defaults to removing nothing from the cache, so you should provide your own filters if you enable cache sweeper.

Note: You can use the `lastInteractedTime` property in the object to implement an NRU (Not Recently Used) cache if you'd like. For example, if you'd like to only remove the members that aren't accessed in the last 15 minutes and isn't the bot member, you can do:

Expand Down
35 changes: 15 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,30 +757,25 @@ export interface CreateProxyCacheOptions<T extends ProxyCacheTypes> {
setItem?: (table: 'channels' | 'guilds' | 'members' | 'roles' | 'users', item: any) => Promise<unknown>;
/** Handler to delete an object in a specific table. */
removeItem?: (...args: [table: 'channels' | 'guilds' | 'roles' | 'users', id: bigint] | [table: 'members', id: bigint, guildId: bigint]) => Promise<unknown>;
/**
* Options for handling the removal of objects that may trigger bulk modifications or deletions of associated entities.
*
* This allows for performance optimization by consolidating multiple operations into a single action, rather than executing hundreds of queries.
*/
bulk?: {
/** Handler used to remove multiple objects in bulk. Instead of making hundreds of queries, you can optimize here using your preferred form. For example, when a guild is deleted, you want to make sure all channels, roles, and members are removed as well. */
/** Handler for the removal of guilds and their associated entities (e.g., channels, members and roles). */
removeGuild?: (id: bigint) => Promise<unknown>;
/** Handler used to remove multiple objects in bulk. Instead of making hundreds of queries, you can optimize here using your preferred form. For example, when a role is deleted, you want to make sure all members who have this role are edited as well. */
/** Handler for the removal of roles and their associated entities (e.g., members having this role). */
removeRole?: (id: bigint) => Promise<unknown>;
/** Options to choose whether or not to replace internal removers. */
/**
* Options to choose whether or not to replace internal removers.
*
* By default, the proxy will handle the bulk modifications and deletions of associated entities from in-memory cache. You can override this behavior by setting this option to `true`.
*/
replaceInternalBulkRemover?: {
/**
* Whether or not to replace internal channel remover.
*
* By default, the proxy will bulk remove channel from memory. You can override this behavior by setting this option to `true`.
*/
channel?: boolean;
/**
* Whether or not to replace internal guild remover.
*
* By default, the proxy will bulk remove guilds from memory. You can override this behavior by setting this option to `true`.
*/
/** Whether or not to replace the internal guild remover. */
guild?: boolean;
/**
* Whether or not to replace internal role remover.
*
* By default, the proxy will bulk remove role from memory. You can override this behavior by setting this option to `true`.
*/
/** Whether or not to replace the internal role remover. */
role?: boolean;
};
};
Expand All @@ -799,7 +794,7 @@ export interface CreateProxyCacheOptions<T extends ProxyCacheTypes> {
};
/** Options for cache sweeper. This works for in-memory cache only. For outside memory cache, you should implement your own sweeper. */
sweeper?: {
/** The interval in ms at which the cache sweeper will run the provided filter functions. */
/** The interval (in milliseconds) at which the cache sweeper should run the provided filter functions. */
interval: number;
/**
* Filters to decide which objects to remove from the cache. Defaults to removing nothing.
Expand Down

0 comments on commit ff87258

Please sign in to comment.