May 13, 2016
Proxy caching allows a server to act as an intermediary between a user and a provider of web content. When a user accesses a website, proxies interpret and respond to requests on behalf of the original server.
For much of the modern web, requests sent to a web service are handled by an intermediate server. This intermediate – or proxy – server processes requests to determine how they should be handled. Proxy servers allow enterprises to structure and safeguard their networks while transparently providing additional features to users.
Proxy caching is a feature of proxy servers that stores content on the proxy server itself, allowing web services to share those resources to more users. The proxy server coordinates with the source server to cache documents such as files, images and web pages.
How Proxy Caching Works
Proxies act as a gateway between the user and the source server, storing (or caching) the server’s resources. When the user attempts to access a resource, the proxy checks to see if it has a recent copy of the resource on hand. If so, the resource is immediately delivered to the user. If not, the resource is retrieved from the source and simultaneously cached to the proxy and delivered to the user.
Step-by-step, here’s how proxy caching works:
- The user’s browser automatically connects to a proxy server. This could be a content delivery network (CDN) which caches content in various locations around the world.
- The browser requests resources from the proxy server. The proxy server checks to see if it not only has the resource, but if the resource is recent. If the resource is old or missing, the proxy fetches a new copy from the source.
- The proxy delivers the resource to the browser. If the proxy had to fetch a new copy, it caches the copy for future use.
Once a proxy refreshes a resource, it resets the resource’s “expiration date” to prevent it from being reflagged as out-of-date. The resource will be delivered as-is until a certain time passes, at which point the proxy server will re-check the source.
Proxy Cache States
Objects requested from a proxy cache can exist in one of three states: fresh, stale or nonexistent. These states are determined by the age and availability of the object on the proxy server as it compares to the source.
Fresh objects are ready to be served in place of the original content. Freshness is determined by metadata which defines either an expiration date or the maximum age of the object. Freshness can also be determined using an aging factor based on the object’s last modification date.
Stale objects are cached objects that are no longer usable. Objects that passed their expiration date or age limit have to be re-cached from the source server before they can be served by the proxy. After encountering a stale object, the proxy simultaneously caches the updated object from the source system and sends it to the user.
Objects that exist on the server but not on the proxy follow the same procedure as stale objects. If an object exists on the proxy but not on the server, then the proxy doesn’t serve the cached copy.
Example of Proxy Caching
CDNs like MaxCDN perform proxy caching on a massive scale. When a user accesses a static website hosted by MaxCDN, content is provided directly from MaxCDN’s servers instead of the original web server. The user only connects to the original server when dynamic content is required or when MaxCDN’s copy is outdated.
Proxy caching allows enterprises to quickly and easily manage their websites. CDNs perform real-time analytics on data, maintain copies of cached content across the globe, and can keep a website up and running even when the source server goes offline.
Benefits of Proxy Caching
Proxy caching makes it easier for enterprises to manage their web services and deliver content to their customers.
- Users enjoy a faster, more reliable experience by retrieving files that are already cached.
- Enterprises see higher customer satisfaction since proxies allow content to be delivered to customers faster.
- Enterprises also see lower administration costs since infrastructure can be outsourced to third parties such as CDNs.
As a web service attracts more customers, it’s vital to have an infrastructure that can handle multiple simultaneous requests. Proxy caching removes some of the burdens from web servers while making content available to more users.
One of the best ways to take advantage of proxy caching is through a content delivery network. To learn more about proxy caching, view this tutorial on setting up a reverse proxy with Nginx.