#Is there a command to clear all the manager caches?
1 messages · Page 1 of 1 (latest)
Since my bot is running on several hundred servers the cache gets very full and nightly reports will not work correctly since I hit the RAM limit.
But the report always seems to work after a fresh startup.
Besides paying more for a virtual machine with more RAM do you have any other ideas?
You can fix it using cache.clear() most likely
But it looks like a Discord.js problem here, as cache should be freed during low free ram
@rain inlet's answer is somewhat good too, but I'm pretty sure that object is used somewhere else too, and it will break stuff. Mine should be fine
yep yours seems a safer way xD
I figure if I clear it out it should rebuild itself.
Is it necessary to call .clear on each cache?
why would you manually empty your cache tho
@rain inlet since you're a sponsor can you summon a dev?
Cache should be freed on low ram automatically
haha it doesn't work like that
I have a report that runs nightly for several hundred guilds. I seem to be hitting a ram limit on my virtual machine.
At least this is my guess since I see memory usage spiking.
have you tried limiting your caches?
And the report runs perfectly fine after a fresh launch of my app.
What is this report all about?
I tried limiting some of them, but I must have limited too much and crashed the app.
You must've been using that evil cache.get that all beginners use and most people suggest to use it there
Here are the different caches I was looking at:
You should almost never use cache.get
@summer torrent i think you may just need to go through each single cache collection and use collection.clear() im not sure tho so dont take my word for it
if you really want to clear all those caches yeah you'd have to go through every single one of them there's no method that clears all of them
In this case, using cache.get could not return the desired result, especially in situation when you're sure the guild is cached..
Those I believe are all the caches. I wish I could find recommended settings for them.
It runs an analysis of player performance at outputs the data is various formats.
If you're using asyncronous code, the cache could be cleared between tasks
Take for example the MessageManager cache. Does each server that installs my bot have their own message cache?
Or is this one cache for all servers?
for all servers
I'm not sure, but maybe client.guilds.cache.clear() may be enough
The GC will take care of the rest
Got it.
I'll give that a shot.
I'm not too familiar with the cache so I appreciate the input.
Learning as I go on this one.
wait actually for the message cache I'm not sure lmao it does not exist on the Client object
yeah each channel object has a messagemanager
which then has the cache
eek...so I would have to clear the cache from every channel that my app can see?
yes yikes
oh boy...maybe I would look into limiting that cache instead lol
I'll have to see if I can find more details on limiting caches.
client.channels.cache.forEach(c => {
if (c.isText()) {
c.messages.cache.clear()
}
})```
you'd have to do smth like this 💀
That's nuts....so if each channel has it's own cache and the default is 200 messages...
Suppose my app can see hundreds of channels, maybe thousands...lol
200*<ChannelManager>.cache.size() is your amount of cached message objects
then just think about it... do you really need to have these messages cached?
Right
I have it set to 20 per channel
but idk what your bot does so
That's might be the cache to go after first. Seems like that one could bloat quickly.
Sounds good! I'll play with it and see what happens! Thanks for your help and thoughts!