V
V
Vadim2015-10-29 18:14:07
PHP
Vadim, 2015-10-29 18:14:07

How to cache a selection from the database and individual page elements?

Hello! The other day I wondered how best to organize caching. The matter is that I have some elements which are deduced once, and are which are deduced depending on request. For example, I get the main menu from the database and there is no need to change it until the end of the session, but every time the page is updated or the link is clicked, the database is accessed. I think that this will create a load on the server. Some pages also contain information that does not need to be updated frequently, for example, the product selection page in an online store, where I get almost all the content using an ajax request and there is a static menu that is large enough and there is no need to update it every time. I read somewhere about session caching and decided to give it a try. I pushed the catalog menu array and the menu array on the product page into the session and now I retrieve data from the database only when the page is first opened, then they are all taken from the session. But it seems to me that this is not correct and can create a greater load than a selection from the database. Please advise how best to organize such caching? There are certainly more effective methods designed for this. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-10-29
@J01

I also found one article here: https://htmlweb.ru/php/php_cache.php
Which method is better to use? This one or the one described in the article?

They are about different things for the most part. The article talks about http headers and describes the caching of pages and blocks to files. And you want to cache data from the database. By the way, Memcache was good when it first appeared and occupied the entire niche, but now Redis bypasses it in almost all respects. And on opportunities, and on speed and on reliability.
And there is also code caching: https://ru.wikipedia.org/wiki/Accelerator_PHP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question