Optimizing Cache Management for a High-Volume Discord Bot
Hello everyone,
I'm currently developing a Discord bot that's active on approximately 1,200 servers, with some servers exceeding 20,000 members. The bot generates a significant number of logs, which is beneficial for monitoring and moderation purposes. However, I've encountered issues related to user data caching: certain user information, such as profile pictures or usernames, becomes outdated because those users aren't present in the cache.
I'm seeking strategies to optimize the bot's overall cache management. Specifically, I'm interested in:
Limiting the cache to store only specific keys or properties of objects.
Implementing more efficient caching mechanisms to ensure up-to-date user information without overloading the system.
I've reviewed the Discord.js documentation on cache customization, including the use of makeCache and Options.cacheWithLimits . While these resources are helpful, I'm looking for additional insights or best practices from the community.
Has anyone faced similar challenges or implemented effective solutions for managing cache in large-scale bots? Any advice or examples would be greatly appreciated.
Thank you in advance!

5 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!if you want to specifically determine which object attributes are kept and sweepers/cache limiters are not sufficient, you will have to do your own caching altogether. discord.js is only as easy to use as it is because of the support of strong caching.
for resource heavy use cases and if you are absolutely sure you only need a limited amount of data from structures you may want to consider using the minimal
@discordjs/core
package instead.
that being said, you will loose a lot of the convenience you get from having clearly defined object instances with known valuesThanks a lot for the clarification, really appreciate it! :robotboyhey:
we've had a system in place at some point that let you define a class that gets instantiated instead of another one
think, CustomUser instead of User, every time the client would normally construct a user
i'm not entirely sure anymore (has been a while), but you could probably also make it slimmer than the original structure
we've dropped that for multiple reasons to do with the same points i've tried to explain above - having a defined set of attributes and values in structures that both the user as well as other library internals can rely on and interact with
another version of that sort of system is on the horizon, but there's no ETA as to when or even if that will happen
i'd say if you have a clearly defined idea of what you want to cache, using the core wrapper is likely going to be more beneficial (you retain the rate limit handling and api interface), but will (as a necessary result, because it is more bare-bones) loose a lot of the convenience you have with the fully cached discord.js
I understand, but first I'll try to optimize as best I can with sweeper and makeCache, and if that doesn't improve anything, I'll consider doing something more complex;
:woah: my dab