Is URL caching a good practice?

I am building up a rather large and complex CMS in PHP, and my plan is to implement caching on some of its parts (with the ability to turn on / off the cache for certain pages / sections). After some research, I came to the conclusion that using a URL would be best practice for finding and returning a cahced file. My intention is to implement a "whole page" solution, to avoid an obsessive request and cache the entire page, for all pages that need to be cached.

The pseudo-code will look like this (exception with a modified date):

$filename = md5($the_full_url); if (file_exists($filename)) get_cached_file($filename); else write_cached_file($filename); 

Can this approach be considered good practice?

+4
source share
1 answer

I think it depends on whether there is user content on the page, for example, if I view the page and you view the page, we get different pages or both pages? Is there any form of “dynamic” content on the page.

Full caches are the most economical if the page will not be changed per user / user. If they can be changed by the user at his own discretion, you can cache [url.sessionid], if not then caching with the full URL.

Another alternative is to cache parts of the page that seem to remain persistent (e.g. blog entries)

Finally, there is data caching in which you simply cache dynamic data from the database locally.

The whole system depends on your requirements.

+6
source

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


All Articles