Content Delivery Networks (CDNs) accelerate web traffic across the internet through servers residing in strategic locations (known as points of presence or PoPs) across the globe. Each PoP has a number of caching servers, each of which contains a cached version of your website or application. By bringing content closer to each visitor, CDNs improve performance and reduce load on the origin server – caching is the raison d’etre for CDNs.
The reason for this is a CDN’s effectiveness can be measured by the cache hit ratio, which is the percentage of requests the CDN was able to serve out of its own cache. The higher the caching ratio, the better your website or application performance. CDNs typically cache static files, such as images, JavaScript files and CSS. This type of content rarely changes and can be heavily cached.
While response and fast load times are crucial for users, the freshness (or accuracy) of your content is no less important for your business reputation.
Caches are refreshed based on the caching policies each website defines, which determine the amount of time a given resource remains in the cache. When that duration expires, the content must be retrieved from the origin server. If the content in the origin server has changed, the new version will be uploaded to the cache.
In certain situations, however, you may not want to wait for the caching period to expire. An example of this would be an update on your website’s pricing page or a bug on an online game. That’s where cache purging comes in. Purging refers to the active removal of a resource from the cache without waiting for the predetermined cache expiry time. As soon as a user requests the purged resource, the CDN will cache a copy of the updated content from the origin server.
If you’re the owner of a blog or an online academic journal whose content doesn’t change once it’s uploaded to the site, you most likely can do without purging since your content is not time-sensitive.
Other types of websites, however, such as news and sports sites with live updates, or e-commerce sites with frequent pricing changes, would benefit from caching policies that reflect the almost continuous information updates. This ensures that content is always fresh without requiring frequent cache purges.
However, there are situations in which rapid purging can be critical for your business and your users. Consider, for example, the following “crisis” scenarios:
In addition to the above, there are applications and websites with cacheable content where certain types of business activities will trigger the need for an immediate purge. For example:
If you need to respond quickly to business triggers or handle an emergency fix, and your changes need to be propagated across the CDN immediately, rapid purging is the answer.
Once you’ve decided to purge the cache, the time it takes to execute depends on your CDN. The effectiveness of a purge request is measured in the time it takes for it to propagate worldwide through the entire network. The speed of the purge depends on several factors, including hardware type, network size and the number of CDN customers requesting cache purges at the same time.
While some CDNs, like Imperva’s, can achieve purge times of less than 500 milliseconds, CDNs with larger networks and outdated hardware may take longer to propagate the request and delete the relevant content from all the caching servers. Most CDNs let you purge a specific resource on demand, but some only give you the option of purging the entire site cache.
Most web developers and website owners want the ability to control their cached content in a manner similar to how they manage their database. This means that the CDN caching mechanism should be easy to use and allow instant propagation of changes or fast purging.
Fast purging means near real-time syncing between the origin server (the application database) and the CDN. It’s designed to minimize the delay between updates to the application resources, such as database and files, and updates of the cached resource, allowing website owners to be in full control of what their visitors see. The first graphic below shows data on all PoPs are instantly synced. The second graphic shows the PoP serving traffic to the user is not synced in time, resulting in a data integrity issue where the user can only view old cached content.
In our experience, we’ve seen that purging is a last resort that should be reserved for exceptional situations. The best way to avoid cache purging is to implement efficient caching policies that reflect the behavior of your website or application. Imperva provides intelligent caching functionality that identifies resources that change more frequently and automatically sets the caching rules accordingly. This gives customers an optimal default refresh policy, so content always stays fresh. These settings can be manually adjusted as needed.
That said, the Imperva CDN is built for rapid purging, comprising a relatively small number of high-capacity PoPs that allow for instant propagation. Imperva users can clear the cache as needed using the following methods:
The Imperva GUI lets you purge the entire cache or a specific resource.
After a major change to your website, such as a version update, you may want to clear all resources in the cache immediately without waiting for the caching period to expire. Just click “Purge Cache” and “Continue” and you’re done.
Clicking “Purge specific resource” will display the following screen:
Select one of the URL rule options to specify a particular URL (URL is) or a string to be matched (URL is, URL contains, URL starts with or URL ends with). Then click the Purge button.
Using the GUI is simple but it can take a couple of minutes to login and execute the purge. It also needs to be repeated each time you update a specific piece of content.
The Imperva API automates the purge cache action. Here the customer must define in advance the types of updates that will trigger an automatic purge like an update to an HTML page. A piece of code is added to the application that calls the API in the pre-defined conditions. The purge is propagated in less than half a second. The API call can be used to purge the entire cache for a site or a specific resource using the resource name as a parameter.
This rule purges all cached content on the Imperva proxy servers for a specific site. For example, you may want to purge the cache after making adjustments in your site. To purge the entire cached content for the site, just use the API call with no parameters. If you want to purge a specific resource, add the resource name in the purge_pattern parameter.
This script adds this rule with these other parameters of the rule, as defined in the Site Management API.
site_id
purge_pattern — The pattern of the resource to be purged from the cache
Sample response to the command, when successful, is
{“res”:0,”res_message”:”OK”,”debug_info”:{“id-info”:”9123″}}
The API offers a more advanced option because it requires some software development on the application side. The decision to use a manual approach or API will depend on your application’s sensitivity to data integrity, as well as the volume and frequency of changes. If it’s low, use the GUI; if it’s high, use the API.
CDN caching gives websites and web applications an effective way to reduce bandwidth costs, improve user experience and ensure reliable content delivery. At the same time, your visitors also expect continuous access to fresh content.
Fast purging allows real-time syncing between the state of the application and the content being served to users from the CDN. It’s particularly useful for reacting quickly to business triggers and crisis situations where you can’t afford to wait for the cache to refresh automatically. For this reason, whether you’re using a manual or automated purge mechanism, speed is of the essence and propagation times across your global CDN are critical for staying on the same page as your users.
Learn more about Imperva Application Performance here.
The post How Cache Purge Helps Keep Your Website Content Fresh and Responsive appeared first on Blog.
*** This is a Security Bloggers Network syndicated blog from Blog authored by Luke Richardson. Read the original post at: https://www.imperva.com/blog/purge-cache-keeps-content-fresh-responsive/