Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Required - no need to cache anything.
Addition from dimasmagadan : Don't forget about setting up the server so that the client's browser can cache pages itself.
Ideally, the data of ALL function blocks that depend on input parameters should be cached.
These include:
1. SQL queries and responses
2. search on any data structure and the result of this search
3. file structure located on a specific path
4. data received for each of the view blocks ("list", "selection", "statistics", etc.)
5. content generated by the template engine based on GET parameters
Always cache the block that takes the longest time firstwhen processing data, etc. descending.
The first contenders for caching, as a rule: blocks with points 2, 3 and 5.
Addition from Aleksey Ukolov :
Caching is a big pain for a developer, in fact. And "no need to cache" - this is from this point of view. Any cache complicates the application at times, because it needs to be disabled, handle errors, etc. But often you can’t do without it, this is a fact.
Heavy places that can hang the site under increased load.
For example, data on the main page, or dynamic content displayed without registration.
Imagine that 1000 people visit the site at the same time, just on the main page of the site. What exactly the loading in such a system rests on is what it is worth caching, if possible, so that the loading of this data does not rest on the database or disk, but is loaded, for example, in finished form from RAM.
Required - I don’t cache anything
When a stream of users arrives, I cache what can be cached so that the load drops
I usually cache everything for guests (at least for 5 minutes, but I always put it in the cache)
for registered users I give the current version of the page bypassing the cache.
the rest is all very specific, depending on the type of caching you are using (nginx, varnish, memcached, or maybe you mean something else by caching)
preferably anything that doesn't have to be rendered every time (rarely changing). for example, it is not necessary to render a category tree every time the page is loaded. cache it, and reset the cache after changes, either manually or triggered by events
It is necessary to understand "why caching is needed", then the question "what to cache" will disappear by itself.
Everything that creates an unnecessary load on the server should be cached. Complex data samples, results of complex calculations.
For example, you have a list of users online and your code iterates through the list of users and checks if this user is in this list or not. Thus each time forming this list. Having cached it for only 1 minute - you will get a performance boost. Even with 1 request to the server. An abstract example, for those who like to be clever - in the garden.
The question was asked incorrectly. The correct question would be "how to collect statistics on requests to pages and functions in order to determine what needs to be cached."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question