Everything You Need to Know about WordPress Object Caching

Everything You Need to Know about WordPress Object Caching

Speed is a contributing factor to your site's success, but it's also one of the most difficult areas to diagnose problems with. If you haven't already tested your site, Google's PageSpeed Insights Tool lets you know if your site could use improvements. Each suggestion will help you speed up your site, but WordPress developers can take advantage of an internal  API called WP Object Cache. This API reduces the number of queries sent to the database server by storing specific option data in a temporary table.

Caching Basics

Every time your visitors open your website, the content is retrieved from the backend database (most likely MySQL). The database processes queries and returns data to the web server. The web server then renders the results.

This process is fine for low-traffic sites, but imagine that you have a million pageviews a day. If each page has five queries during load time, you have five million queries sent to your database every day. The load on your database can be significant enough to degrade performance, which your visitors will experience. A slow website has a tremendous effect on your visitor retention. With just a 4 second delay, you've potentially already lost 25% of your visitors.

If you do a search, you'll find several types of caching. You can cache on the web server using its memory. You can use browser caching to force the user to keep data on their computer. Proxy servers can cache data for enterprise users. WordPress has its own API and type of caching called object caching. It is specific to queries made on stored options coded into themes and plugins.

Caching's main objective is to speed up your site, so any kind of caching is a benefit, but you might not always have the ability to control some kinds of caching. The WordPress Object Cache API is openly available to your developers, so it's a way to speed up your site without changing any server configurations.

More about WordPress Object Cache

While most caching options store content or pages, WP Object Cache uses the options stored in your theme or content. Each plugin or theme that you install on WordPress has its own options that it stores. WordPress has an Options API that stores each value. The most commonly used functions are add_option()  and get_option(). The Options API stores options in the database, so each time an option is retrieved a database query runs. It's not uncommon to have a dozen or more options in just one page of a WordPress site.

The Object Cache API stores specified objects in the database for one page load. One page load might seem like a short lifetime, but it's enough to increase the speed of your site. You cut the number of queries on your database in half (or more), because each time the user loads and reloads a page, only one query is needed for dozens of options.

WordPress has just a few Object Cache functions. The gist of the functions is that you add data to the cache with a corresponding key that is used to retrieve it again. You can optionally group data to use the same key across several options. A expiration time in seconds can be set on the cache. The default is 0, which means that it persists forever or until used but you can set a numerical value to delete cache for certain instances such as when the data might become obsolete.

WordPress also has a Transients API, which works similarly to the Options API, except Transients require an expiration time (in seconds). Transients’ data can also be stored in memory rather than the database. The Transients API should be used carefully, or it could cause technical errors on your site.

Redis with Object Cache

Redis (REmote DIctionary Server) is an open-source database store that uses in-memory stored data that sits as a "go-between messenger" for your MySQL database and the front-end of your WordPress application. It speeds up your site even more by providing an in-memory cache that WordPress can interact with instead of using MySQL resources. It's mainly used for data structures such as lists, maps, sets and sorted sets. If you have complex data storage, Redis is a performance upgrade option.

In terms of WordPress, Redis is popular for caching. It has other features, but caching is its main benefit when working with a WordPress site. You can use plugins to interact with Redis, or design a custom one to work with key features that you want to support on your site. The combination of storing data  in a way that is easy to retrieve, and keeping it in memory make Redis a great addition to performance optimizations  on your site.

Where to Go from Here?

The first step is to identify if your site has any speed issues. Google PageSpeed Insights is helpful, but you can also use GTmetrix as an alternative. You can find suggestions on what you can do to speed up your site, but if these suggestions don't offer enough of a performance boost, it's time to take other measures.

You can use plugins from the WordPress repository that implement Object Cache and Redis, but your options are limited. In some cases, it's better to build a custom plugin specific to your own site.

Whether you go for a custom plugin or a pre-made one from the WordPress repository, caching is an important part of performance optimization that you can leverage for a faster site. Take a look at your site’s speed to determine if it’s time to implement some of the available caching methods.

What is Static Page Caching for WordPress?

Poor website speed is a killer for any website. With today's broadband speeds, consumers no longer accept dialup speed load-times. A slow website can be a sign of a poor quality business, so page speed should be top priority when you design and build your web presence. According to surveys done by Akamai and Gomez.com, half of your visitors expect a website to load in two seconds or less. If your site loads in three seconds, you've already lost 79% of your potential sales. Website speed is the foundation for your site's success. Build a strong website on a fast foundation, and the sky's the limit. Have poor speed, and your website can fall apart at any time.

Every second counts in website design, so even the smallest change can have enormous benefits in terms of speed. One change that's a lot less complex and low cost than many other performance enhancements is caching. Several factors go into site speed, but caching can shave several seconds off of a slow website and decrease page load time to less than 100 milliseconds.

Understanding the Way a Web Page Works

Before you can understand caching and its benefits, you should first understand the way a web page renders in a user's browser.

Each time a customer types your business URL into a browser, the browser first does a lookup for the IP address using DNS. After the IP is found, the browser requests the URL's content from the server.

Twenty years ago, it was common for a website to have standard, static HTML pages. These pages did not change regardless of who, when, or where the page was rendered from. There was no database storing information for pages to load. It was just a static page that did not change.

As technology evolved, databases were integrated into web development. Take a standard e-commerce store as an example. The e-commerce pages display products based on a user's queries. Most elements on an ecommerce page are dynamic, including the main content, breadcrumbs, and parts of the navigation menu. Each time a page is requested, the web server makes a call to the database, waits for it to process the query, and retrieves the data. The web server then renders the data on the page dynamically.

As you can probably guess, a dynamic page takes much longer to load because of the processing time between sending a query to the database server, waiting for it to process the request and then waiting for it to return the data. The entire process takes milliseconds, but it leaves a lot open for performance degradation. Too little bandwidth, poor programming, or a slow database can hinder performance.

How Caching Works

Several elements on a web page never change. Images, CSS and JavaScript files, footers and headers rarely change. These elements change when there is a major upgrade but stay the same for months at a time. They don't use data from the database, so no dynamic content is loaded.

Caching speeds up your site by storing these files in RAM (AKA "cache"). Loading content from RAM is much faster than loading from a hard drive. Since static files don't change, the server moves them to RAM, so each time the content is requested it's loaded from the fastest storage component available on the server.

With page caching, you can also store dynamic pages that still load dynamic content but where that content remains the same for a long period of time. For instance, your navigation page could be dynamic but it stays the same until you deploy an upgrade. Caching stores common dynamic pages and their data that are requested frequently. Any page stored in cache (RAM) speeds up the website load-times, but remember that each page uses some of your memory. You should determine which pages are requested frequently enough to cache them, because too much caching can exhaust server resources.

WordPress also has an internal API that allows a developer to control caching objects. Developers can create plugins specifically for WordPress sites and reduce the number of times pages make calls to the database.

Testing Your Site

You might not  know if your site needs to use caching, or that it's loading too slow. There are two main testing tools on the market.

Google PageSpeed Insights is a speed tool that tests your site on both desktop and mobile devices. It even gives you suggestions on what you can do to speed up your site. Compression, caching, and minifying elements are three areas Google will give you advice on should your pages load too slowly

Another major tool is GTmetrix. It's less popular because it's based on Yahoo's speed guidelines. It's still a good way to ensure that you've covered all possibilities for your site's performance.

Remember that you don't need to comply with every suggestion. If your pages load quickly, then having compressed images or browser caching might not be necessary. It's up to you and your developer to decide which caching options are necessary to keep a site within recommended load times.

Sample Benchmarks

If you’re curious about facts and results, WP Dev Shed has an excellent table of speed results from various plugins on the market. The table should help you decide which one is best for your site.

WordPress also has an API that lets developers manipulate cached objects, so you can customize caching using a developer and some innovation. If you want the fastest speeds available for your site and customers, caching is an inexpensive way to give your WordPress site a speed boost.

 

Why we use Amazon Route 53 for DNS

Stability and Reliability with Amazon Route 53 DNS

Without stable DNS, your software will never be reliable. DNS (Domain Name Service) is the backbone protocol that translates long, generic IP addresses to friendly, recognizable domain names. Amazon Route 53 DNS is compatible with both IPv4 and IPv6. If you don't have reliable DNS, your customers won't be able to find your site when they type its address into their browser. You need a DNS solution that stays active and reliable 24/7 to ensure that your customers have access to resources all day, every day.

DNS is used both internally and externally in the Amazon ecosystem, and using Route 53 reduces much of the technical overhead.You could use your own DNS solution, but it requires technical know-how to configure records properly. You also don't have the massive reach of Amazon's global locations with basic DNS services provided by a standard provider. AWS powers world-class, high-end DNS services for your enterprise, so your servers are never unavailable due to a DNS failure. Amazon Route 53 is more than just a domain-to-IP protocol service. It also offers disaster recovery failover solutions, geo-proximity settings, latency-based routing, and domain name registration services.

One option that sets Amazon Route 53 solutions apart from other e-commerce hosting platforms is its globally present data centers. AWS data centers are available in 44 different zones and 16 geographic regions. When your entire operation relies on the stability of IT infrastructure, you want the best service available so that you never experience a 2am phone call to tell you that your site is down. With Amazon services, your site data replicates across a lightning fast backbone to each data center. When users request service from your application, the data center within closest proximity replies, making your services as fast as possible regardless of the user's location. If one data center fails, traffic can be re-routed to another to keep your business running. AWS is ideal for international businesses that can't afford even a minor blip in uptime.

With the numerous AWS centers available to you, your replicated services are protected from critical outages. AWS has several triggers and health checks to ensure that DNS is always available. If a health check detects no response or even a time-out or slow response, a CloudWatch alarm is set and a notification sent to the appropriate recipient.

With Amazon's reliability and stability, it's no wonder they are host to over one million enterprise customers. It's why SourceCode Partners chooses to support our customers on  the best cloud solution available on the web. When you host in the cloud using AWS, you leverage the largest and most trusted cloud host in the world.