Does the included cache include dynamic content?

Does the included cache include dynamic content?

For example, on one of my PHP sites, the cache header is:

Cache-Control: public, max-age=21600 

Does it also affect dynamic content?

If so, what is the standard way to cache a dynamic PHP site? Presumably, you will cache static content (e.g. images), but not dynamic content (e.g. html, text, etc.). How and where could you do this?

+4
source share
2 answers

Yes. The answer is yes. This controls the browser and some ISP caching. It will cache dynamic content for the time specified in many places. Not all. Not all browsers will follow the rules, not all Internet providers will follow the rules. AOL is known to ignore user caching rules and cache everything for weird times, resulting in broken pages on an early website.

On a dynamic page that is not cached, you can use this value to set pages that change relatively often in the cache 10 minutes before an hour. For images, css, js files and things longer. Caching for 8 hours is probably too much, since it far exceeds 1 hour, but only reduces the total number of views for content by 7.

Other caching

There are other, possibly more reliable, ways to cache content. You can see query caching, file caching, memcached. All of these options can also be used to cache things other than content. All of them will help you speed up repetitive actions.

Request Caching

Many defacto MySQL databases offer query caching. This will cache query results in tables that have not been updated since the query was last run. Ideal for normalized lookup tables. Ideal for tables that are updated only once in the blue moon. Works well for tables that update about once per hour, and even every 10 minutes. For tables that change more often than they do, they will create limited temporary results.

File Caching and Memcached

They can be used to cache key / value pairs. They can be page_url / page_content or page_list / array_of_pages_in_site or any other key / value pairs you need. Thus, today, most people use page caching for 10-60 minutes. They are reliable, monitored on the server and can be immediately cleaned if necessary. They should not be time-based, if your logic is spelled correctly, you can consider them as a query cache. Only when the information is updated, do you clear this key from the cache, and then instantly refresh the page and otherwise sit in the cache.

Header cache

Which brings us back to the header cache. It is still prudent to cache here for about 10 minutes, even with other caches in place. Other caches still require server requests, which can slow it down. Although this will not reduce this pressure, it will reduce it. And it does not require much effort to install.

+3
source

The idea is that your website is made up of resources [pages, images, scripts even], and you provide an expiration limit for each of them, or you donโ€™t have a cache for the elements you changed [for example. You have added a new message on the homepage or edited the post].

A common solution is to use a reverse proxy , such as Varnish , which will provide caching very quickly to the client, and will look for newer versions if the cache header has changed in your content.

The process of the cache header generator is up to you - you can find a few ideas here .

0
source

Source: https://habr.com/ru/post/1436149/


All Articles