N
N
nosooqua2019-09-10 00:18:00
MySQL
nosooqua, 2019-09-10 00:18:00

What is the best way to work with a database?

Good day. There is a Minecraft game server. It is planned to work with a database of this type: get/write information about an item, get/write a list of players and the number of this item he has, get/write a list of items that will be contained in the item. Question such - as it is better to work with a DB? Access the database as needed (the player has opened an interface in which there will be things from the database -> get things from the database), or every N minutes save information to memory / file, and already read it all from there? Thank you very much for your answer, and sorry for the (possibly) stupid question)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitsliputsli, 2019-09-10
@Vitsliputsli

In general, work with the database as with the database, you need to write - write, you need to read - read. Everything else is optimization for specific performance drops, and they need to be applied when there are any, because. any optimization is not free, you always sacrifice something.

S
Smittyperm, 2020-01-14
@Smittyperm

Usually development happens like this:
First, everything is always read from the database and stored in the database immediately. It is easier to do this, it is more difficult to produce errors, the first prototype will be faster, bottlenecks and crooked queries to the database are immediately visible.
If at some point a situation arises with very frequent access to the database, then the data begins to be cached in memory.
Someone makes a lazy cache (On the example of a chest and things in it: if there is data about the things of this chest in memory, then we use them. If not, then we load from the database).
Someone initializes the cache at the start of the application (We load data at the start of the server about all the chests and things in them).
As for working directly with the database, I can advise you to look at https://github.com/aaberg/sql2o

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question