Welcome to Sydney Business Web Technical Solutions Problem 2 - Cache Bloat
Every day, we solve problems for eCommerce website owners. We had a think about how we might use this activity to help others, and came up with this idea: Every week, we'll take the trickiest problem and publish our solution.
Important! - Some of these solututions involve adding code to your website (WordPress and Woocommerce mostly), so please ALWAYS be careful. We are not in any way responsible, directly or indirectly for any impact or consequences our code or advice has on your website, nor are we liable for any damage arising from such use.
Always back up your website before changing or adding code and/or editing the database, This is critically important!!!
PROBLEM 2: Cache bloat and 503 responses
The Hidden Danger of Cache Bloat on WordPress Websites
The immense flexibility and power of WordPress make it a go-to platform for many website owners. However, as with any digital system, it's not immune to issues. One such problem that can remain largely invisible until it wreaks havoc is cache bloat. If you run a WordPress site, especially one with a large volume of content such as e-commerce sites powered by WooCommerce, it's essential to understand cache bloat and its consequences.
What Is Cache Bloat?
Cache bloat is a situation where an excessive number of cache files accumulate, taking up too much storage space and potentially causing operational issues on a server or hosting environment.
In an ideal scenario, caching serves to speed up your website by saving a static version of your site's pages. This means visitors don't need to fetch the same resources repeatedly, thereby reducing server load and improving site speed. However, when not managed properly, the very system meant to increase efficiency can become the source of your website's downfall.
How Cache Bloat Affects WordPress Sites
1. Surpassing File Count Limits
Most shared hosting environments impose limits on the number of files a website can use. When a website, especially a sizable one like a WooCommerce store, uses caching plugins such as W3 Total Cache, it can quickly generate a significant number of cache files. This can lead to scenarios where file limits are exceeded, resulting in server errors like the dreaded "503 Service Unavailable."
2. Impact on Site Performance
While the primary purpose of caching is to improve site speed, excessive caching can lead to the exact opposite effect. If your hosting server is continuously scanning through hundreds of thousands of cache files, it can strain the server resources, causing slow performance or even downtime.
3. Limitations on Backend Access
As cache bloat becomes a severe issue, you might experience difficulties accessing your WordPress backend or certain cPanel functionalities. This can make it even more challenging to resolve the problem since you might be unable to clear cache from the WordPress dashboard directly.
Mitigating Cache Bloat
Prevention is always better than cure. Here are some steps to prevent or address cache bloat:
- Regular Monitoring: Regularly monitor your file usage, especially if you're nearing your hosting's limit.
- Plugin Settings: Ensure you have configured your caching plugins correctly. Some plugins offer settings to limit the number of cache files or auto-purge them after a certain period.
- Manual Cleaning: In extreme cases, accessing cPanel or your server's file manager to manually delete cache files can be necessary.
- Consider Upgrading: If your website is growing, consider upgrading to a hosting plan that offers more resources.
Conclusion
Cache bloat can be a silent menace for WordPress website owners. While caching is instrumental in optimizing site performance, it's crucial to manage it effectively. By understanding the potential risks and monitoring your site, you can enjoy the benefits of caching without falling into the pitfalls of cache bloat.
Results
Our problem was that a long-running Woocommerce website with only 4,000 products was suddenly out of file space and using 220,000 files from an allowance of 200,000. We could not log into WP and many pages were giving a 503 response (as was our login attempt).
After inspecting the site on CPanel we discovered the cache bloat and deleted trhe cache folder (as an experiment) andf disabled the W3 plugin. This reduced file count to some 86,000. We renabled the cache. Within less than an hour the file count was again 220,000. NOTE: We should have inspected the W3 settings but we were losing patience and needed to fix this fast on the live production site. So we DON'T blame W3 entirely.
We installed a new cache plugin and checked the file-count after a day. File-count was 84,000 - a reduction of almost 140,000 files. We do accept that W3 cache has been an excellent solution for a long time, and that we may need to investigate the settings we used as things change over time, but if we can suffer like this then so can others - so keep an eye out of cache bloat on your site - it can kill your performace and site availability.
NOTE: After 2 says the total files were up to 120,000. We are keeping a watchful eye on it! If necessay we will write some code to clear cache files every 2 days or so.
NOTE: Another 2 days later and the file count is 83,000. It seems that the n ew cache (Litespeed Cache) controls the file-count nicely. We are now closing off this article.
Need help? -