Apache Cache is a free and open-source caching proxy server that works behind the scenes to increase user experience by speeding up your website’s performance. It’s been around for just about a decade now, but what was once an obscure project has since been adopted by many webmasters and developers. That’s because it’s a very powerful tool that can increase the performance of just about any website.
What does Apache Cache do?
In a nutshell, it stores frequently-used content in memory and on the hard drive. That way, it can serve that content much more quickly than if it had to retrieve it from its origin server or database storage for each and every request. You can think of Apache Cache as a “local copy” of your website — one that’s stored on your web server and improves performance by reducing database access and bandwidth usage (i.e., fewer HTTP requests).
Afrohi Storama says, Apache Cache is especially helpful for dynamic websites, which have a lot of scripts, databases, and other “moving parts.” Each script and database hit slows your overall performance down. The more scripts and databases you have, the slower it gets. Cache can help to alleviate this problem by caching scripts and static content so they don’t need to load over the network every time a page is requested.
How Apache Cache Works
There are two basic components to the Apache Cache system: The front-end (cache manager) and the back-end (cache engine). The cache manager is a user-interface with a few basic features that allow you to configure slow responses, purge content from the cache, and even manually flush the entire cache from your web browser.
The back-end cache engine is where all of the real work happens. It’s a daemon process that stores content received from the origin server and serves it back to your visitors.
It works by receiving a request from a visitor’s web browser, going through memcached first (if enabled), then checking its local storage area to see if it has a copy of the requested content. If not, it will then retrieve that content from disk or over HTTP and store a copy in its memory or on disk once again for future use. This process is all done transparently and will continue to repeat itself as long as the visitor’s browser is connected to your web server.
Apache Cache and Website Speed
It’s true that Apache Cache can make a website load faster — but more importantly, it can make a site more useful for your visitors as well. A cache can improve overall site performance because it reduces the network requests that users experience. It also reduces the amount of time it takes for those requests to be fulfilled, which is especially helpful if your site does any heavy lifting behind the scenes.
Because of its strong caching system, Apache Cache can work with any web server and works with any web application — not just on WordPress sites. But for this tutorial, our examples and screenshots will be demonstrating it within the context of a WordPress installation — mainly because we can easily use it to increase performance.
WordPress and Apache Cache
The real power of using cache with WordPress is that the content already exists in a format that’s compatible with Apache Cache. So when you add cache to your site, it doesn’t rewrite your pages or change the HTML. Instead, it just makes them load much faster because they’re being served from cache instead of requiring an HTTP request each time you access them.
This is especially helpful if you have a lot of dynamic content and want to avoid unnecessary database hits and slow loads. Even though the content is dynamically created, you can still use cache to serve it faster.
Custom post type
One example of this is using a custom post type called “videos” with Kaltura for video embedding. Using cache, you don’t have to constantly ask your WordPress database for each video’s ID and then feed it into another system to display the correct video each time a page is loaded. Instead, you can store all of your videos in memory so they only have to be retrieved from the originating Kaltura server at most once, if ever.
It’s also helpful if you have many WordPress sites on your server. You can configure Apache Cache to handle all of the databases, pages, template files, and plugins for each site. And since it can be set up on any type of WordPress installation, you can use it to boost the performance of an entire network of sites.
Apache Cache vs Memcached
Apache Cache is written in PHP5 and works with any web server running it. Memcache is a comparable service in PHP, but was written in C over ten years ago and is only supported by a handful of servers at this point in time. That being said, if your web host supports memcache-server , many popular servers include support for it. So you can use memcache if you’d like. But for the purpose of this article, we’ll stick with Apache Cache and compare it to memcache-server.
How to Set up Apache Cache
The first step in setting up cache is to install and enable the module on your Apache web server. This process varies depending on which server you’re using, but should be relatively simple (just don’t get scared by the long wordy installation instructions). If you’re already using other modules or addons provided by your provider, then it’s highly likely that they provide documentation detailing how to set up other addons.