D
D
Dmitry2014-09-16 10:26:05
PHP
Dmitry, 2014-09-16 10:26:05

Does it make sense to store cache in MySQL database?

I went to an interview, where they surprised me with the question:
[employer] Where do you store the cache?
[I] In the files naturally.
[employer] Strange, the database would be better.

What I cache: ready-made data in the form of a serialized array.
Total question: is it better in files or in the database? (we are talking about regular shared hosting, no bells and whistles)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2014-09-16
@mytmid

Under the cache, people often understand a lot of different things.
It is possible and necessary to store some kind of pre-generated content in files, for example, static pages that change orders of magnitude less often than they are read (and at the same time generate for a long time) and give them directly to the user, without the participation of scripts.
Storing a serialized array in files is, in my opinion, absolutely not correct.
The file system is slower than sql and has a bunch of places that everything can rest against (the number of files, iops, etc.). It is no coincidence that people who use the session mechanism built into PHP are first of all recommended to transfer it at least to sql.
Your potential employer is also not very right by the way.
Caching data obtained from it in SQL is butter oil :)
If you really want to cache data - cache it in memcache, redis, etc. - there the data is stored in memory and will really be quickly given back to you.
Well, or denormalize the data structure in sql, so that the data that used to be considered a long complex query is now already calculated. But don't call it cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question