Some of my thoughts:
You can save page caching for a certain period of time, for example, one hour or 15 minutes. This time depends on the number of visitors that you receive on the page, the frequency of changes in details and your personal preferences. Because it really doesn’t matter if the number of user posts is out of date. After this period, delete the cached version (also save resources), and if the page is visited again, it will be overwritten with updated data.
With the clever (re) use of ob_start() you can buffer several parts of the page, for example, part of the mail and part of the comments. Keep these parts separate, and you only need to restore one part instead of a full page. In most cases, the postal part does not change very often.
Keep track of the pages on which the user posted comments (or the page itself, if he created it). After making changes to user data (adding new posts / comments), make these pages obsolete (i.e. delete the cached version). If you have a lot of changes over a short period of time, you can use some kind of background process to re-cache the pages and maintain your web server.
Inserting tokens (unique pieces of text, for example% user: 123, postcount%) of frequently changing details is another possibility. Then save this version in your cache and at the request of the page you can replace the tokens with your data. It can also be combined with other caching methods if the number of page views over a period of time is very large (or at least much higher than the frequency of changes in the part).
Veger source share