H
H
hesy2020-05-12 17:51:58
PHP
hesy, 2020-05-12 17:51:58

What data can be stored in the cache, and what is better in the database?

Good afternoon!

I wondered what data should be stored in the cache (memcached), and what is better in the database?
It is clear that the password should definitely not be stored in the cache :)

A simple example is to generate an authorization code that will be valid, for example, for 5 minutes.
There are two solutions:
1 . Write the authorization code to the cache, specifying the period - 5 minutes.
2 . Write the authorization code and creation time in the database, and check the relevance using the cron (either at the time of the call, but here it is possible to clutter up with old codes, and again you have to clean it with the cron)

The 1st option looks the prettiest, but will such an implementation be correct?

Please share other examples

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-05-12
@FanatPHP

Store data only in the database.
The data is not stored in the cache. Generally. "Store data in cache" is an oxymoron. Cache is the opposite of storage. The storage guarantees the availability of data, and the cache does not guarantee anything, and in the absence of data it crawls into the storage.
The cache is used to speed up access to data, not to store them.

R
Roman Mirilaczvili, 2020-05-12
@2ord

Memcached is worth storing (short-lived) user sessions. Sessions do not store passwords, only generated IDs.
Passwords are needed by the server only at the stage of user identification.
Also, read FanatPHP 's answer .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question