Shopware HTTP Cache inefficient
The goal of the Shopware HTTP Cache is to have homepage and as many category and product pages pre-rendered from a cache without having to query the database or external systems at all.
Cached pages are much faster, often 10 times as fast, as uncached pages. Having a page rendered from the cache also reduces the load on database and external systems.
It is therefore desirable when using the HTTP cache, that the ratio of of pages rendered from the cache vs uncached pages is high. This is called the "cache hit rate" and is computed as follows:
Cached Pages / (Cached Pages + Uncached Pages)
In any Shopware 6 shop the following factors influence the cache hit rate:
-
The environment variable
SHOPWARE_HTTP_DEFAULT_TTL
defines how many seconds a page is cached after which it will be considered uncached again. The default value is 2 hours (7200) and for shops with moderate traffic this can be increased. -
Cache invalidation can be triggered by Shopware or by plugins and invalidate a few or all pages in the cache. If this happens regularly, then the cache hit rates will decrease.
-
When users are logged into Shopware, the cache is not enabled by default. If you have a large number of logged in users, but the content on product or category page is not uniquely tailored to them then it makes sense to modify the caching strategy to include logged in users.
-
When products are in the shopping cart the cache does not activate anymore with the default settings.
-
The Shopware Rules API affects the cache hit ratio, because each rule can potentially affect the output of the page. You can audit the active page rules for ones that make the cache inefficient.
You can find a lot of information on cache specifics on this blog post from Daniel Wolf (German).