Fundamentals and Implementation of WooCommerce Cache
Speed is paramount when it comes to ecommerce. Whether you’re chasing down better search rankings or attempting to curb cart abandonment, the speed at which a store loads can determine how many customers convert. Caching in WooCommerce is an essential performance tuning tool that can dramatically decrease page load time. In this article you’ll learn about two techniques to help you cache your WooCommerce store and how it can increase the performance & speed of your store.
A quick note before getting started: Underlying code and database performance issues should be addressed before implementing a caching layer.
What slows a website down?
On a web server, complex computer processes are most often triggered by code (ex. PHP for WordPress and WooCommerce) and database queries (ex. MySQL).Submitting commands (whether PHP, MySQL or another programming language) for a computer to process generally happens quickly.
What takes precious time is waiting for the computer to process the information and deliver the results to the potential customer waiting in front of their computer screen. When requests become complex or there are too many requests for a server to process then you’ll want to look into three methods to speed the interaction up: caching, concurrency (increasing PHP workers), and reducing complexity (making code more efficient).
What is caching?
When a user requests a web page (like a homepage) that isn’t cached, every time the page is requested, database queries are executed, PHP code runs, and the resulting page is displayed in the customer’s web browser. The entire process can happen pretty quickly.
If many database queries are required, the logic to draw a page is complex, or you have a high volume of traffic, the process of outputting the page to the visitor can slow considerably, which means longer than normal wait times.
Caching is the process of converting a piece of dynamic data into a static resource. Or put another way, caching is the process of saving the results of a request from a complex computer process and re-routing future identical requests directly to the result, skipping the computer processing.
Output caching, also called full page caching
When it comes to pages that don’t change very often (like content pages such as an About Us page), output caching is a great technique to create a fast experience for potential customers. Here’s how it works:
- A web page (for instance a product category page) is requested by a potential customer.
- When the page is requested, WooCommerce interacts with the database to determine which products to show along with the pricing, description, images etc.
- This cached HTML is served every time someone visits the same page.
There are a ton of full page / output caching plugins on the market. My favorite is WP Rocket because it has a slick user interface that makes configuration a snap. A great free option is Cache Enabler, and it’s available in the WordPress.org repository.
Object caching, and speeding up database access
In some common ecommerce use cases, we might not want to cache the entire page of the website. For instance, we might not want to cache order status, shopping cart, or product pages with customer specific pricing as these pages might change more often than an output cache is refreshed.
So, if we can’t cache the entire page, and the database is the bottleneck, caching queries to the database is a great way to speed things up — that’s exactly what object caching is all about.
Consider for a moment that a customer might switch between a product page with customer specific pricing, shopping cart, and order status pages multiple times during their logged in session. On a site not integrated with an object cache, the database would receive a request to process a search every time a user switched between these dynamic pages.
Here’s how object caching works to make database interactions quicker:
- A query is presented to the database server via PHP code.
- When query results are requested, the database searches to find the result.
- After the database finds the results, they’re saved in a cache on the database server.
- This cached result is served every time a piece of code requests the same query.
When object caching is enabled, dynamic parts of a WooCommerce website will load quicker and put less strain on the database server leading to a better experience for the end user.
Setting Up Redis
Redis a popular object caching tool and can be difficult to set up depending on your skill level and the level of server access that’s provided by your host.
For a simple setup, Redis comes automatically set up for all Managed WooCommerce plans at Nexcess.
Or if you want, you can set it up yourself.
A quick note on troubleshooting
While implementing caching can lead to awesome performance gains, it can also make it more difficult to troubleshoot output issues. Remember to disable caching when trying to uncover an output issue.
Caching in WooCommerce is an essential tool for dramatically improving the performance of your store. Have caching questions? Feel free to give us a shout day or night. We’re here for you.