Fix Library: Performance and caching
Full Page Cache Not Working
Last updated:
What you see
Pages are slow every time, even on repeat visits, and the full page cache does not seem to do anything.
Quick answer
Most often one block on the page is marked as uncacheable, which makes the whole page uncacheable. Other causes are the cache being turned off, Varnish not being used even though it is set up, or something clearing the cache all the time. This is the short version; the blog post has the full walk through.
What usually causes it?
- A layout block with cacheable="false" on common pages
- Full page cache disabled, or set to the built-in cache when Varnish is expected
- An integration or cron job flushing the cache too often
- Cookies or headers that stop Varnish from caching
How do you check it safely?
These checks only read information. Run them on staging first if you can, from the Magento root folder as the file system owner. Hosting setups differ, so paths and service names may need adjusting.
- Check that the full page cache is enabled.
bin/magento cache:status - Check which cache application is configured (1 = built-in, 2 = Varnish).
bin/magento config:show system/full_page_cache/caching_application - Request a page twice and compare the headers. With Varnish, the Age header should grow on the second request.
curl -sI https://www.example.com/ | grep -i -E 'age|x-varnish|cache-control|x-magento' - Search custom code and extensions for uncacheable blocks.
grep -rn 'cacheable="false"' app/code app/design vendor/*/*/view 2>/dev/null
How do you fix it?
These steps change your store. Run them on staging first, with a backup of code and database.
- Remove cacheable="false" from blocks on common pages and load customer specific content through private content (customer data sections) instead.
- Enable the full page cache and set the cache application to Varnish if Varnish is installed.
bin/magento cache:enable full_page bin/magento config:set system/full_page_cache/caching_application 2 - Find what flushes the cache and change it to clean only the cache tags it needs.
When should you call an expert?
Call an expert if the cache works on some pages but not others, or the hit rate stays low after these fixes.
Need it fixed today?
I can look at it with you. Book a 20 minute call, or if the store is down, see emergency Magento support.
Further reading
FAQ
Common questions.
Why does one block break caching for the whole page?
Magento caches whole pages. If any block on the page says it cannot be cached, Magento cannot store the page at all.
Is the built-in cache good enough?
For small stores it can be. Adobe recommends Varnish for production because it is faster and handles more traffic.
Related
Rather have it fixed for you?
Send a few lines about the problem, or book a 20 minute call. You get an honest read and a fixed quote.