<p>I'm having troubles with my site being super slow. It seems like caching isn't working. When I upload the site to a different server, everything seems fine.
When I empty the template cache and load the page, there are ~9000DB queries which take about 7s. On the page where the caching works, on the next page load only 55DB queries are necessary which take 2,6s.</p>
<p>The only differences I'm aware of now regarding the servers is, that the &quot;slow&quot; one is running with MySQL 5.5 and NGINX while the other uses 5.7 and Apache.</p>
<p>What needs to be installed or configured on the server for caching to work? I do use <code>{% cache %}</code> tags in the twig-code.</p>

CC BY-SA 4.0
2021-02-08T08:29:39.947Z
I think 9000 database connections is a big number, I never observed that much with any of my sites (using crafts debug toolbar). If this number is related to a very big and complicated site, then you probably cant just use the cache tag to ameliorate the page load time. On the server where you think the caching does not work, do you see new files being generate in storage/runtime/cache and storage/runtime/compiled_templates ?

This article is a little older but has been updated by Andrew lately: https://nystudio107.com/blog/the-craft-cache-tag-in-depth
MisterMike
CC BY-SA 4.0
2021-02-08T15:56:57.580Z
I deleted the two folders (cache and compiled_templates) and yes, new files are generated. So it means that caching works, right? What else could be the reason for making this huge amount of DB queries over and over again?
The "craft_templatecaches" table, as mentioned in the article is empty on both servers.
I know it's a lot of queries and when doing research I came across Eager Loading. I will try to implement it, but I don't think this will be the final solution, since even the status quo can run fast, as the second server shows.
obs
CC BY-SA 4.0
2021-02-09T09:42:59.667Z
Check if any page of the website has 9000 db queries, meaning you'll have to narrow the queries down. Maybe you're doing something repeatedly where you are unaware on its implications to the db. But without knowledge of the code, its hard to tell.

The final solution is something where you "fix" the queries and where caching is working. Something invalidates the template caches, so while the files are being generated, they get replaced with new ones on every request. That said I could imagine these two issues stick together..
MisterMike
CC BY-SA 4.0
2021-02-09T09:53:16.883Z
But when the cache get invalidated, why would it work on one server and not on another? I thought there is some issue with the server configuration, don't you think?
obs
CC BY-SA 4.0
2021-02-09T10:39:08.353Z
I cant tell you from here what is being served to the browser in terms of the cache. Check both site conf files. Check both .env files, check for devMode. 

You certainly should start profiling your site. What does the debug toolbar tell you about the most time consuming db query? You can sort by execution time ("duration") to find the slow queries.
MisterMike
<craft3><templating><cache>
Cache not working
# Cache not working

(Asked by: username_0 on 2021-02-05)

I'm having troubles with my site being super slow. It seems like caching isn't working. When I upload the site to a different server, everything seems fine.
When I empty the template cache and load the page, there are ~9000DB queries which take about 7s. On the page where the caching works, on the next page load only 55DB queries are necessary which take 2,6s.

The only differences I'm aware of now regarding the servers is, that the "slow" one is running with MySQL 5.5 and NGINX while the other uses 5.7 and Apache.

What needs to be installed or configured on the server for caching to work? I do use `{% cache %}` tags in the twig-code.

**Tags:** craft3, templating, cache
> **Comments:**
> **username_1**: I think 9000 database connections is a big number, I never observed that much with any of my sites (using crafts debug toolbar). If this number is related to a very big and complicated site, then you probably cant just use the cache tag to ameliorate the page load time. On the server where you think the caching does not work, do you see new files being generate in storage/runtime/cache and storage/runtime/compiled_templates ?  This article is a little older but has been updated by Andrew lately: https://nystudio107.com/blog/the-craft-cache-tag-in-depth  
> **username_0**: I deleted the two folders (cache and compiled_templates) and yes, new files are generated. So it means that caching works, right? What else could be the reason for making this huge amount of DB queries over and over again? The "craft_templatecaches" table, as mentioned in the article is empty on both servers. I know it's a lot of queries and when doing research I came across Eager Loading. I will try to implement it, but I don't think this will be the final solution, since even the status quo can run fast, as the second server shows.  
> **username_1**: Check if any page of the website has 9000 db queries, meaning you'll have to narrow the queries down. Maybe you're doing something repeatedly where you are unaware on its implications to the db. But without knowledge of the code, its hard to tell.  The final solution is something where you "fix" the queries and where caching is working. Something invalidates the template caches, so while the files are being generated, they get replaced with new ones on every request. That said I could imagine these two issues stick together..  
> **username_0**: But when the cache get invalidated, why would it work on one server and not on another? I thought there is some issue with the server configuration, don't you think?  
> **username_1**: I cant tell you from here what is being served to the browser in terms of the cache. Check both site conf files. Check both .env files, check for devMode.   You certainly should start profiling your site. What does the debug toolbar tell you about the most time consuming db query? You can sort by execution time ("duration") to find the slow queries.  

---

## 0 answers

