V
V
Vadim Stepanenko2018-05-17 17:01:33
PHP
Vadim Stepanenko, 2018-05-17 17:01:33

Correct output of values ​​from the database?

Hello!
The page displays information about the user (login, avatar and other static information is stored in the session), but the question arose, how to display the balance?
If you display it simply by taking it from the database, then will it not fall, say, with 1k+ online, which update the page quite often?
There was an option to save in the session and make a refresh button, when clicked, a request is sent to the database and resaved to the session, but it does not fit.
The same question, for example, to the blog. The user opens a page with records and they are loaded directly from the database? Or are they stored somewhere and removed from there?
And the last question: for example, on the main page there is a balance, entries from the blog, entries from other "modules". And remove them all from the database? Same for 1 page at least 10 requests
Thanks in advance for your replies. If this is a stupid question, then don't throw stones.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery, 2018-05-17
@it_monk

You can use memcached and cache the user's balance in it using the "$uid.balance" key, for example. And when changing the user's balance, delete the value by key.

S
Sergey, 2018-05-18
Sysa @absorberex

If you want to store from the session, you can take information about the balance from the database on the first visit and save it to the session.
If the balance changes, the session is updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question