How to make sharding and caching work together?

* Today I added sharding * I use a caching system for my bot * My bot is used in both servers and DM. Problem: If each shard uses its own caching, data will get desynced (e.g. a configuration is set to true in shard 0 but not in shard 1). Solution: Only have one shard (shard 0) use caching. Any suggestions on what would be the best approach to make this work? I'm asking because I'm not even sure I fully understand shards. From what I understand there is one client created by the shard manager that has shard 0. In that case I think I should do the following: 1. Check what shard its at. 2. In case of shard 0, do normal caching stuff. 3. Else, get the caching info from shard 0. But then I'm not even sure how to have it check its at shard 0. In any case, any tips on how to make this work would be appreciated.
7 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sheepolution
SheepolutionOP3y ago
I meant a configuration in my database. That the caching between shards results in data different than what's in the database. I don't want to change the shard they're on, and I'm using shard 0 because of the very reason that its used in dms
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sheepolution
SheepolutionOP3y ago
Let's say my database keeps track of players. In a server they can play a game (using my bot) and the data of this game is added to the database. It keeps a counter of how many games you played. 1. You check your stats in DMs. It says 5 games, and this is now cached. 2. You play three games in a server. The server is on a different shard. It updates your total games to 8. 3. You check your stats in DMs again. It still says 5 games, because this data was cached.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30003y ago
You could also delegate caching externally to smth like redis
Sheepolution
SheepolutionOP3y ago
I suppose I should do that yeah. Currently my caching is storing a whole class instance. Hmmmm
Want results from more Discord servers?
Add your server