D
D
Dmitry2014-05-18 21:11:16
PHP
Dmitry, 2014-05-18 21:11:16

Data caching when developing a site in PHP - what is it?

I heard a couple of times about such a thing as caching in relation to the development of sites, engines, etc. I can't figure out what exactly is being said. Is it about page caching? Those. there are dynamic pages (the data for which is taken from the database), but the content of the pages does not change for some time and, accordingly, this data can not be taken from the database every time, but taken from the cache. Do I get it right? But what then in this case is CACHE? Browsers themselves have caching, but that's not the point.
Plus, there is one more situation: for example, on each page of the site a vertical menu of services is displayed, a large multi-level menu, which is also taken from the database. The menu is the same on all pages. And every time you navigate within the site, making queries to the database to get this menu is not very rational, because the menu remains unchanged. Accordingly, if I understand correctly, the menu also needs to be cached and not climb into the database every time to display it. Am I correct or not? Is this what they are talking about when they talk about caching in engines?
If so, how is this caching implemented in PHP?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
denver, 2014-05-18
@battrack

You need to cache something that slows down AND changes much less often than it is shown. If nothing slows down, or frequently changing data is cached, using caching can slow down more than not using it.
If the site does not change at all (business card, portfolio), then you can generally cache the entire resulting HTML (using ob_start() ob_getcontents(), or instruct varnish to do this). Most often, the content of the pages is non-static and blocks need to be cached. Most often, these are HTML blocks (like your menu). Sometimes it is even data (daily aggregation, top of the best of something).
Some commonly used storage types are described here:
itechtalks.blogspot.com/2011/09/php-data-caching-t...
(they also forgot about apc, redis, memcache, etc.)
Of the completely different types, there is also mysql query cache - caching of query results, but this is rarely useful. There is also opcode cache (php accelerators) it's just useful to enable so that php files are parsed less often.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question