Caching Your Way to a Faster Website

Caching is one of those terms that has seemingly been around since the dawn of computer age. But what, exactly, is it and how can (should?) it be used when it comes to websites?

Definitions and Performance

At its most simple definition, caching is a temporary storage space or memory that allows fast access to data. Caching often gets defined by its use case. There are at least five major cache location types utilized by web developers today.

First is object caching, which saves an application object locally so that it can be served for future requests without requiring retrieval from the origin server. Next, database caching allows you to cache query data in memory buffers to increase database performance. Bytecode caching, such as OPcache, improves PHP performance by storing precompiled scripts in shared memory, thereby removing the need for PHP to load and parse scripts on each request. Page caching stores action outputs as an HTML file that the web server can serve immediately without going back through the on demand (dynamic) retrieval of data. And finally, distributed content caching uses geographically distributed server memory to deliver content faster.

While the differences may appear subtle, in actuality, these have very different uses to optimize the performance of any given website. We’ll go over how some of them are used later on.

Power for Performance

Caching is dependent on the hardware that powers it. The faster the hardware, the faster the caching mechanism can pull the requested information.

The slowest speed is a regular, old fashioned hard drive that can pull 200 megabytes per second (MB/s) and 100 inputs/output operations per second (IOPS). A Solid State Drive (SSD) pulls 600 MB/s and 300,000 IOPs, a considerable improvement. However, SSD is  nothing compared to the speed of RAM, which pulls data at a whopping 20GB/s and four million (!) IOPS.

The speed of your cache, regardless where you cache, is directly related to the speed of the storage type used for the cache. Thus, newer, faster hardware is preferred to make sure your  website operates at peak performance.

Caching and your Hosting Solution

When choosing a hosting environment for your website, it is critical to pick one that meets your RAM needs and configurations. While having too many resources isn’t a serious problem, having too few can lead to major ramifications to your website’s usability. We’ll look at how shared, dedicated and Virtual Private Cloud (VPC) hosting differ in RAM and how these differences can affect the caching potential, and, ultimately, the performance of a website.

Shared hosting

The most common (and generally most cost-efficient) type of web hosting, shared hosting places many websites on a web server that’s directly connected to the internet. A common iteration of shared hosting is distributed hosting, in which a cluster of servers distributes a website’s resource needs to each of the servers in the cluster, like a power grid (similar to Media Temple’s very own Grid).

With shared hosting, the speed of the service is linked to the amount of RAM and the type of storage provided. You won’t have robust resources or power-user access, but at the very least, you should expect 200MB of RAM alongside SSD-powered storage.

Dedicated & Virtual Private Cloud Hosting

When it pertains to caching, Dedicated and Virtual Private Server (VPS) hosting may be different in name but are fundamentally similar types of hosting, as both provide power-user access to isolated resources.

Dedicated hosting provides a whole private web server with complete access via Linux or Windows Admin. Once again, your preference should be for a large amount (or at least an appropriate amount to your needs) of RAM and SSD-powered storage. While the SSD storage will power your database / webpage storage for fast retrieval, it will rely on different caching configurations to use your RAM to deliver the webpages. Crucially, within a dedicated server you can host your own virtual machines (VMs), aka miniature computers, that will run within the constraints of your web hosting.

VPS hosting, on the other hand, is web hosting where a user receives their own isolated VM. The hosting provider provisions the requested resources from their network and allocates them in a way that does not directly reflect the underlying hardware. Much like dedicated hosting, VPS has a wide variety of uses since you’ll have complete control of all the assets and can run multiple services that can maximise resource utilization. Once again, the amount of RAM and type of storage will determine the speed of your site alongside the type of caching you implement.

The Power of the CDN

One way to speed up your site is through a hosting add-on product called a Content Delivery Network (or “CDN”). The CDN is a network of servers that delivers web pages and other web content based on the geographic location of the user, the origin of the webpage, and a content delivery server in closer proximity to the user.

cdn key

The CDN is a truly clever solution to improve website load times. By distributing web resources to a server closer to the user, the CDN will shave off precious milliseconds of loading time by caching images, videos, uploaded files, JS, CSS, and even HTML.
Choosing the right CDN can be difficult. I’d recommend looking at companies such as cedexis that provide helpful free statistics that can help you decide on the CDN for your needs.

A Case Study: Media Temple’s Enterprise WordPress

Earlier this year, we launched  Enterprise WordPress, a new enterprise-grade WordPress offering that combines managed WordPress hosting, Amazon Web Services (AWS), 24/7 premium technical support and dedicated account management. Enterprise WordPress utilizes a wide variety of caching mechanisms to provide its users with the fastest cloud hosting experience available. Our seasoned cloud architects pick out the right page loading optimizations for a client’s uses, removing that worry for those that don’t want to pick a caching plugin themselves. There is a general hierarchy we use, as you can see in the image below:

aws style

Almost every type of caching we’ve mentioned above is used to power sites on Enterprise WordPress. Firstly, we have tuned MySQL server to improve database caching. Object caching is done on separate servers, fully in RAM. Secondly, PHP scripts are all cached in shared memory via OpCache, so there is no need to reload a script upon each request. Then, page caching is handled both on a proxy server and on separate servers fully in RAM so whole HTML files can be delivered upon request. And finally, to ensure each site’s user receives all the assets from the closest possible source, a CDN is utilized to house and deliver all static content.

The combination of multiple levels of caching not only ensures that data is delivered quickly, but also that the site can handle a large number of simultaneous users. Who says you can’t have the best of both worlds?

Essential Caching Plugins

Thankfully, there are plenty of caching plugins already out there to help maximize the performance of your sites. Here are some of the most popular:

  • W3 Total Cache – This is the all-in-one caching optimization that is used on millions of WordPress sites worldwide. Compatible with almost every type of hosting, this plugin includes page, database, and object caching via shared disk or Memcached for almost every web asset available. This plugin is like a swiss army knife and even has additional features such as minification and even monitoring integration to a popular monitoring tool.
  • Redis Object Cache – This is a persistent object cache backend powered by Redis, the open source in-memory data structure storage. This plugin has a simple UI. Of note: This is not to be used in a shared hosting environment.
  • BatCache – Another object caching plugin, BatCache uses Memcached to prevent traffic surges from breaking a site. Installation requires copying files over and making configuration file modifications and has no UI. For users using a Memcached server, they should strongly consider this plugin. Of note: This is not to be used in a shared hosting environment either.
  • WP Super Cache – Want fast file-based page caching? WP Super Cache is your ticket – it generates static html files of your WordPress site to serve to users as opposed to creating dynamic pages on the fly. This is great for both shared hosting or single server hosting.
  • WP Rocket – Excellent for shared hosting, this paid plugin focuses on page and browser caching alongside caching preloading. Easy to install and customize (and with a great support team to boot), this plugin offers a slew of site-side tweaks like lazy loading and font optimization.

Have any questions or additional tips and tricks for caching? Add it in the comments below!

Comments

  • Matt McKinley

    Very helpful! I’m eager to try out a couple of those caching plugins.

  • Great stuff, we used to use two of those but have since switched to WP Rocket combined with Amazon Cloudfront. Is there any reason why Varnish isn’t automatically installed and setup on MediaTemple’s VPS servers? Seems like it would be a no brainer.

  • Have tried many setups and if the site is running on wp, I would allways go with this setup: w3tc + Cloudflare

  • Hasan Raza

    A very well written article by fellow Eugene. Choosing the right hosting also contributes a lot in site speed, as in case of managed cloud hosting provided by Cloudways. But factors such as server location also matter a lot in site speed so it is recommended to host on server location nearer to targeted audience.

  • Ironic that the W3 Total Cache or WP Super Cache aren’t allowed on a MediaTemple WordPress site…

    • Although it looks like they have some kind of implementation of their own.

  • Ilya

    Any caching options for non-wordpress site on MediaTemple’s Grid?

Related Articles