Tired of slow page load times and constant frustration with your WordPress site’s performance? The solution might just be something called ‘Object Caching’.
In this article we’ll dive into exactly what Object Caching is and how it works. Most importantly, we’ll guide you through the steps you’ll need to go through to start using Object Caching to significantly improve the speed and efficiency of your website.
Say ‘goodbye’ to sluggish load times, and ‘hello’ to a lightning-fast, smooth user experience.
Let’s get started!
What is Caching?
Caching is a technique used to store frequently accessed information in a more accessible and responsive location. If processing a website request takes a large amount of time then it can degrade the user’s experience, potentially impacting your sales and conversions on a regular basis.
Caching can help solve this problem by storing the frequently required data in a fast-to-access storage location. Any data that is accessed frequently and can be stored for a while is a good candidate for caching.
Caching is often associated with RAM, but it can be used with any storage media. For example, if downloading information from a server over the network takes ten seconds, you can save time by caching the file on your hard disk.
If reading the data from a hard disk takes too long, you can speed it up by caching the file in your RAM, which is many orders of magnitude faster than a hard disk.
Taking this one step further, you can even cache some vital information directly in the cache memory of your CPU if the delay caused by reading the data from RAM is unacceptable.
Although it is useful, caching is not a silver bullet. Cached data becomes outdated after a period of time, and this can cause unexpected glitches in the application. To ensure proper functioning of your application it will be necessary to constantly replace the old copy of data with a fresh copy at regular intervals.
One more thing to keep in mind is that as we shift towards faster storage media, the capacity decreases drastically along with the exponential increase in the cost. For example, cloud storage costs a few dollars a month for hundreds of GBs of storage. Modern SSDs are getting cheaper, but still cost hundreds of dollars for a single terabyte of storage. RAM is much faster than an SSD, but most modern computers only have about 16GB of RAM. As a surprise to no one, the cache memory size of a CPU is even lower. The Intel Core i9-13900 processor – the latest offering from Intel – still only offers 36MB of cache memory.
Overview of Different Types of Caching
- Server caching: When the server processing the requests caches the queries, then it is called server caching. In WordPress, there are two main types of server caching techniques:
- Object Caching: In this, WordPress stores the results of frequent database queries and other API requests. It is called Object Caching because the result of the query is often an object (such as an item of data from a database, a row from a table, or a document).
If you want to display the result of a complex database query, such as the number of 5 star reviews on a particular product, then Object Caching is the right choice for you as the number of reviews are likely to remain the same when a page is refreshed. - Page caching: This type of caching involves generating complete static pages and storing them. When a server receives a request, it serves this statically generated page instead of rendering a fresh copy of it.
If you are serving pages that mostly remain the same, but are heavily requested by your users, then you should use this. The homepage or the pricing page of your site are unlikely to change often and are a good fit for this type of caching.
- Object Caching: In this, WordPress stores the results of frequent database queries and other API requests. It is called Object Caching because the result of the query is often an object (such as an item of data from a database, a row from a table, or a document).
- CDN caching: This is a good option for caching static content, such as images, fonts, CSS, JS libraries, and HTML pages, on a content delivery network (CDN). If your site uses a CDN, then all of your customers’ requests will be routed through a CDN. If the CDN has a cached copy then it serves that, otherwise it asks your server for a fresh copy, serves that, and also stores it for future use. When the cached copy gets too old, it is automatically deleted and the CDN asks for a fresh copy.
Although this might seem like extra effort, this drastically reduces the number of requests that reach your server, and it also serves content faster to your visitors. - Browser caching: This is somewhat similar to CDN caching, but it happens in the user’s browser. If a user is visiting your site for the first time, they won’t notice a difference. However, returning users would already have a cached copy of your data and won’t need to make network requests; this can drastically reduce the request time.
Sometimes, even first time users will be able to take advantage of browser caching. For example, if you use third party assets such as Google Fonts or Google Analytics on your site, and the visitor has previously visited a different site that also uses these same assets, then the browser will already have a cached copy of them, and can use those.
What is Object Caching?
In WordPress, Object Caching is the technique of storing the results of complex database queries in memory. These saved results are then reused when executing subsequent requests and, since the results are already computed, it takes less time to serve those requests.
Object Caching reduces the load on the database and improves the overall performance and responsiveness of a WordPress site. As a result, you can serve more customers without needing to scale up the infrastructure, helping to save on server costs (and significantly improve the user experience).
When Do You Need Object Caching?
If you already have a CDN configured on your site then you might be thinking that you don’t need to use Object Caching. While a CDN does help in reducing the server load, it can’t replace Object Caching – no one particular caching solution can solve 100% of your problems.
A way to think about caching is as a series of nested filters, where each filter catches smaller and smaller things at each level. As data passes through each level of caching, it is checked against increasingly specific and targeted rules until only the most relevant and frequently accessed data remains in the cache.
Any WordPress site that receives a high volume of traffic, has complex queries, or requires fast and reliable performance, can benefit from Object Caching. Here are some scenarios where Object Caching can be especially beneficial:
- High-traffic websites: Publishers and news sites that receive a high volume of traffic can benefit from Object Caching to improve page load times and reduce server load. Object Caching can help reduce the number of database queries required to load a page, which can make a big difference when dealing with large amounts of traffic.
- eCommerce sites: Online stores that use WordPress plugins such as WooCommerce, Easy Digital Downloads, or NorthCommerce can benefit from Object Caching to improve the performance of their product pages, shopping cart, and checkout pages.
- Course websites: WordPress sites that use a learning management system (LMS) such as LifterLMS, LearnDash, or SenseiLMS can benefit from Object Caching to improve the performance of their course pages, quizzes, and other interactive features.
- WordPress multisite networks: Websites that use WordPress multisite networks can benefit from Object Caching and improve the performance of their entire network. Object Caching can help reduce the number of database queries required to load pages across the network, which can improve the overall speed and responsiveness of the sites.
What Are the Benefits of Using Object Caching?
Object Caching can offer several benefits for WordPress sites:
- Improved Performance: Enabling Object Caching can significantly improve the performance of WordPress sites by reducing the amount of time it takes to serve a request. By caching commonly accessed data, such as queries or API calls, Object Caching can eliminate the need to repeatedly fetch the same data from the database. This can improve the speed and responsiveness of the site, resulting in a better user experience.
- Better Lighthouse Scores: Object Caching can directly impact your Lighthouse Scores. A properly implemented caching strategy will reduce Time To First Byte (TTFB) and First Contentful Paint (FCP) – these metrics are important factors in determining Lighthouse scores. Having a good Lighthouse score is essential for a snappy user experience – and it also improves SEO.
- Reduced Server Costs: Object Caching can also help to reduce the load on the server. Caching the response of commonly requested database queries leads to a reduction in the number of requests sent to the database. This reduces the load on the server, and ultimately reduces the amount of resources needed to serve the site. This can result in lower hosting costs and better scalability for WordPress sites.
What is WP_Object_Cache?
The WordPress engine provides a built-in Object Caching functionality that can be accessed via the WP_Object_Cache class, (a ‘class’ being a blueprint for a way data should be structured). This class acts as a layer between the programmer and the underlying architecture where data is processed. It’s not recommended to use the class directly – you can use pre-defined functions to set, clear, add, and update cache values.
Object Caching is typically achieved through the use of an external caching solution, such as Redis or Memcached, which acts as a fast, in-memory data store for cached objects. When used correctly, Object Caching can result in significant improvements in page load times, increased website stability, and a better user experience.
What Are Redis And Memcached?
Redis and Memcached are open-source database technologies. These are key value store databases which can each be thought of as a dictionary. In other databases, such as MySQL or MongoDB, you can store multiple values in one record, but in a key value database you can only store one value in each record.
For example, an SQL database can be thought of as a table that contains all the test scores of a student. The student might have scored well in the last exam, or they could have been absent. All this information can be stored in the table, the design of which can be modified to add or remove information.
SQL table:
In the case of a key-value database such as Redis there is only one field, and it cannot be modified. This is best visualized by imagining a dictionary which can only hold one definition for one word, and nothing else.
In this example, a key value store saves the value of a complex query which was run on above database:
No_of_students_absent | 2 |
Avg_marks_of_Steve | 24.3 |
Redis stores the data in RAM for much faster access compared with storing it on the hard disk. This simple architecture makes Redis, and other similar databases, ideal for storing cached data.
Both Redis and Memcached are designed to be used with a variety of programming languages and platforms. The key difference between the two is that Redis supports more advanced data structures, such as lists and hashes, while Memcached is simpler and focuses on the efficient storage and retrieval of key-value pairs.
Object Cache Pro – A Better Caching Solution
Object Cache Pro is a high-performance Object Caching plugin designed to meet the needs of mission-critical businesses. It offers a combination of performance, scalability, and reliability, which are essential for any high-traffic website. The development team uses test-driven development methodology with over 1,000 unit tests to ensure every update is safe and offers warnings about plugins that can lead to data loss.
It’s designed to provide a smooth user experience, with tools to help identify issues, built-in query monitoring, and logging. Additionally, it’s fully customizable and works even when Redis is not on the same machine, making it ideal for horizontally scaled environments of two servers or more.
How To Use Object Caching With WordPress
If you’re already a RunCloud customer then getting started with Object Caching is very straightforward, as our RunCloud Hub enables you to turn on caching with a few simple clicks.
With RunCloud Hub you don’t need the expertise of a server administrator to reap the benefits of caching – you can do so by simply installing the RunCloud Hub plugin and enabling the caching option. This installs all of the dependencies automatically, and configures them on your WordPress website.
For a more detailed guide on configuring caching, refer to our other articles:
- How To Use Redis Full-Page Cache
- How To Use Nginx FastCGI Cache
- NGINX Caching Tutorial for WordPress
- How To Configure Object Cache Pro for WordPress
If you’re not using RunCloud yet, you can still use Object Caching in WordPress by installing either the Redis Object Cache or Memcached Object Cache plugin.
Both of these are popular choices for Object Caching in WordPress, and the decision of which one to use depends on the server environment. Redis Object Cache is known to work well on servers with high CPU usage, while Memcached Object Cache is better suited for servers with limited memory.
Although these plugins provide a caching functionality for WordPress, they do require you to have access to a caching server. If you are using a shared hosting service you may need to contact your hosting provider for this. If that’s the case, then you should consider switching to RunCloud which makes it easy to manage your servers – and allows you to set up caching with only a few clicks. Sign up for managed hosting with RunCloud today!
After Action Report – Get All The Benefits of Object Caching When You Deploy With RunCloud
Improving website loading times is crucial for delivering a positive and responsive user experience, and can directly impact your website’s search engine rankings. Using caching is a smart and cost-effective solution to achieve faster website speeds without having to spend more money on hardware or infrastructure upgrades.
An absolute essential for any mission-critical business site, let alone any serious website – caching can significantly reduce the load on your database and improve load times by storing the results of expensive computations.
Whether you choose to set up caching on your server using Redis or Memcached plugins, or use an all-in-one solution such as RunCloud Hub, we’re sure you’ll be pleased to see the benefits of object caching.
If you aren’t quite comfortable with the idea of deploying servers and setting up object caching entirely from scratch, we’d love for you to give RunCloud a try (for free).
We built RunCloud so you don’t need to be a system administrator or Linux expert to manage your cloud infrastructure. With everything from backups, staging, cloning, atomic (Git) deployments, and more – we’re on a mission to make it truly enjoyable to manage your own production-grade infrastructure. Learn more & get started today.
If you have any questions about Object Caching or need help getting started, leave a comment below or tweet us on Twitter. We’ll be happy to help!