#Questions about Caching
1 messages · Page 1 of 1 (latest)
get uses cached information inside the bot and fetch makes an API call so the speed depends on the resources of discord and you connection, not your hardware.
And about how long things are cached : It depends.
If the bot is on a server for example the class corresponding to it won't disappear as long as it's on it.
But if you're talking about thing that were fetched I don't think they disappear as long as you don't manually clear the cache.
It's hard to say without knowing the framework by heart or by examining its structure.
I think the opinion of one of the contributors here would be welcome
And are there any advantages of get over fetch other than speed?
I don't think so
Ratelimits
And for some stuff, object returned by get has more data than that of fetch
Eg fetching a guild wouldn't give you the members. Only the in cache one would
but you could fetch the members though.
But ratelimiting is actually a good example. But what I'm always struggling with is whether the object is cached or not. So when is an object put into cache and when is it removed?
True you can fetch the members but you gotta have the id.
If your concern is whether the object is called or not, first get it, ig that returns None then fetch it. Safest way. Some objects also have a grt_or_fetch method on it
Objects are put into cache whenever discord sends them over the gateway. Guilds, roles and members are sent on startup, messages on message. And updates on the relevant update events. Roles and members are also updated if they are mentioned in the message iirc
So if I got a Guild by fetching it, and later want to work with that guild again I can just use get? Even if I deleted the fetched guild object?
like
guild = bot.fetch_guild(1234...)
del guild
guild = bot.get_guild(1234...)
```would work?
No iirc
So what would work?