Cache Customisation
So ideally I wanted some help with caching customisation. I noticed that djs caches a TON of stuff that I don't even need. I just wanted to get some support on the proper way to actually cache stuff.
Just to keep it simple, the only thing I need would be guilds size and member count which is taken from the guilds cache itself. How would I go about getting rid of everything else that's less important?
7 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.Pretty much, I use slash commands aswell and have nothing with reactions, messages etc
I just respond to slash commands entirely and that's about the main purpose
You have two relevant options in your ClientOptions object:
makeCache
and sweepers
. makeCache lets you set a max amount of a structure that is cached, and sweepers gives options to periodically remove structures when they have been cache for X time, or you can set a filter function to only remove a structure under certain conditions
So, it's less about white listing the structures you do want to cache, and it's more about blacklisting the structures you want to uncacheI mean I don't wanna cache everything thats not relevant
How could I do that?
Ideally the only thing I want to cache would be guilds
but things like channels etc, do I need that?
The cache is used a lot internally
For instance,
interaction.channel
is just a getter for client.channels.cache.get(interaction.channelId)
: even though you're not using the cache directly, it's still being referenced
People who uncache all roles will get errors since DJS expects the everyone role to always be cached, and when it's not, a type error is internally thrown
Even guild.members.me
is null whenever the client user is removed from the member cache in a guildThe sweeper options tell you a list of most the managers whose cache you can safely limit: https://old.discordjs.dev/#/docs/discord.js/main/typedef/SweeperKey
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
So you recommend me to use sweepers instead?
I was thinking to directly set the cache limit to 0 for bans, stickers, emojis, invites and whatever is cached thats not used internally
Ideally I want to limit everything that djs doesn't use / I don't need
looking at that list, guildMembers and guilds would be the only case
since I've mentioned my use cases for cache above, the rest would be unnecessary unless djs needs it
but this can help me save alot more memory than necessary
Nope
Just
Since I want access to guildCreate and guildDelete
and then guilds cache gives me guild count obv and membercount across all guilds
otherwise, I do not need anything myself
Is there any way to disable everything else? @qjuh
sorry about the ping
meant that as in apologies the disturbance, I got a little impatient
alright