Jump to content

Template caching


matjazp
 Share

Recommended Posts

I've set up the template cashing on the Cashing tab, like 3600 seconds, for Guests only. When I access the page I can see that the cache file is created at /site/assets/cache/Page/ folder. On the next access of that page the content is served from the cache. What I observed is that the caching isn't really effective as my page render time is almost the same. I guess that if the page would be "heavier" the difference would be more significant. It looks like PW takes it's time to boot and there is where most of the time go. What are your observations? Also, when you edit the corresponding template file (aka basic-page.php) and made some changes, those changes are not reflected in the output until the cache expires or you edit and save the page with that template in admin. Can anyone confirm?

Link to comment
Share on other sites

ProcessWire is pretty fast on it's own, so if you only have some PHP templates doing basic output there won't be much of a difference. Though you can probably see the difference by recording page load times in Chrome for requests with and without the cache, respectively. Though you need to do this in a private browser window where you aren't logged in, otherwise ProcessWire won't use the cache, as per your template cache settings.

Two things that I have noticed to slow page loads down are "heavy" queries, e.g. if you query dozens of pages for data, especially if you do it in separate database queries. I'm also using Twig for output, which does come with a small time increase, especially while auto reload is active.

Quote

Also, when you edit the corresponding template file (aka basic-page.php) and made some changes, those changes are not reflected in the output until the cache expires or you edit and save the page with that template in admin. Can anyone confirm?

That is correct, ProcessWire doesn't check timestamps of template files to decide when to serve from the cache. You can manually clear the entire template cache by going to Modules -> Configure -> PageRender and checking the checkbox there. Or use my new Cache Control module, which can clear the template cache alongside a couple of others in one click ?

Link to comment
Share on other sites

1 hour ago, MoritzLost said:

That is correct, ProcessWire doesn't check timestamps of template files to decide when to serve from the cache.

@MoritzLostThanks for confirming that. I guess there must be some reason for that? As PageRender could take this into an account.

@draganThanks for the hint. What is the difference between the MarkupCache module and https://processwire.com/api/ref/wire-cache/? Still, this is something developer should do, it's not on/off solution (and to be fair, template cache would probably also not be good solution for just every template).

Link to comment
Share on other sites

I am using opcache built in php on windows/IIS and it helps a lot. I don't have a problem with the speed of my sites, I'm just brainstorming- wondering why caching doesn't help that much as I expected. But I'm working on my own caching solution and results so far are very good.

Link to comment
Share on other sites

Quote

Thanks for confirming that. I guess there must be some reason for that? As PageRender could take this into an account.

Only Ryan can answer that, but I suppose checking the timestamp every time would have a performance impact (though a tiny one). Another perspective is that checking only the template file might result in unexpected results if you modify an included file, because then the cache wouldn't be cleared. For example, if you're using Twig, the PHP template file isn't modified very often, so it wouldn't work. I actually prefer it this way, that is if the system makes few assumptions.

Quote

Thanks for the hint. What is the difference between the MarkupCache module and https://processwire.com/api/ref/wire-cache/? Still, this is something developer should do, it's not on/off solution (and to be fair, template cache would probably also not be good solution for just every template).

I've only used WireCache because as far as I could tell when I was looking for something similar, it's the newer and better version of MarkupCache. Also, WireCache is already integrated into ProcessWire and ready to go. You can cache any kind of data (array, PageArrays etc) with it, while MarkupCache (as far as I'm aware) can only store strings. I'm using the WireCache to cache render-intensive HTML output and queried data on pages where I can't use template cache for various reasons, and it has a large impact, reducing page generation time on a particularly heavy page from ~2 seconds down to a couple milliseconds.

Have a look at the $cache API documentation.

Quote

I don't have a problem with the speed of my sites, I'm just brainstorming- wondering why caching doesn't help that much as I expected.

Just out of curiosity, what are your tested page generation times for cached / uncached pages? Because in my experience, a simple ProcessWire site will already be so fast out of the box that caching won't do anything, because most of the generation time comes from network overhead and hard drive speed ...

Link to comment
Share on other sites

1 hour ago, MoritzLost said:

Another perspective is that checking only the template file might result in unexpected results if you modify an included file, because then the cache wouldn't be cleared. For example, if you're using Twig, the PHP template file isn't modified very often, so it wouldn't work. I actually prefer it this way, that is if the system makes few assumptions.

This also came to my mind. Although it could be considered as unexpected result even if you don't have includes and the page is not updated when you update the template file...

1 hour ago, MoritzLost said:

Just out of curiosity, what are your tested page generation times for cached / uncached pages?

 I'm testing on localhost, SSD disk, for simple echo "foo" in my template file it takes cca 300 ms in Chrome network panel (Chrome caching disabled).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...