Purging invalidates (removes) a cached object ahead of when it would naturally expire. You may want to purge something because it’s incorrect, out of date, or because you have a breaking update. Once an object is purged, the next request for that object will be retrieved from the source rather than the cache.
There are many reasons why you, as a website owner, might want to purge a cache. For example, if you are an eCommerce retailer, you want to make sure the price or quantity of a product is always up-to-date - a great reason to implement a purging policy. Or, if you have a news website and the headline or content of an article is no longer valid, you would want to purge so that the new title and content will be retrieved from your origin server and stored in cache instead of the outdated version.
How does purging work?
While an object is stored in cache, it has a freshness lifetime, also known as a TTL or time to live, and can be served without needing to be revalidated by the origin server. Once the cached object reaches its TTL value, it expires and the cache is no longer considered fresh. This object may continue to be served stale before it’s formally evicted and the cache is revalidated.
When you need to remove the content from cache before its normal expiration time, you can use purging. This is often necessary when the cached content contains errors, is no longer current, or needs to be updated immediately due to critical changes. Whatever the case, you are purging to replace what's currently cached on your site with a newer, fresh version on your origin.
Methods of cache purging
Now that you can answer ‘what is purging’, let’s move on to examine the various methods of cache purging:
Manual cache purging: This involves manually initiating a purge request for specific content or paths. It could be done through a user interface, API, or command-line tool provided by your caching system or Content Delivery Network (CDN). Manual purging is helpful for one-off or infrequent situations when content needs to be updated immediately.
Automatic cache purging: In this method, purge requests are automatically triggered based on certain events or conditions. For example, purges could be initiated whenever new content is published or updated in your content management system. Automatic purging helps ensure cached content stays fresh without manual intervention.
Purging strategies:
Full purge: A full purge invalidates the entire cache, clearing out all cached content. This heavy-handed approach is typically only used when absolutely necessary, as it impacts cache performance until content is re-cached.
Partial purge: With a partial purge, you invalidate a subset of cached content, such as certain URLs, path patterns, or content types. This allows you to be more surgical in purging just the outdated content.
Smart purge: Some caching systems support more intelligent purge logic based on factors like cache age, traffic levels, or content relationships to minimize the impact on performance while keeping content fresh.
Cache purging best practices
Effective cache purging ensures your content's freshness while maintaining optimal performance. Let’s have a look at the best practices to follow if you want to achieve this balance:
Define which specific scenarios and conditions will trigger cache purging and which purging methods are appropriate (full, partial, or smart) for each situation. Consider your content freshness requirements, criticality, and update frequency when determining your policy.
Schedule regular cache purges, either full or targeted, to clear out lingering stale content and reset the cache. The frequency depends on the nature of your content, with rapidly changing content requiring more frequent purges.
Integrate cache purging with your content management system, CI/CD pipelines, or other tooling to automate purges based on content updates or deployments. Automation ensures timely purges and reduces manual effort.
Purging, especially full purges, can temporarily impact performance until content is re-cached. You can test purging workflows, implement throttling or rate-limiting and consider intelligent purge logic to minimize the impact on your origin servers.
Continuously monitor the effectiveness of your purging processes, track metrics, and refine policies and workflows as needed. Be prepared to adapt strategies as your requirements or technologies change.
What is an example of purging?
Let’s say you publish a news article but notice there is a mistake. You correct the article and push it to your origin servers using your deploy process. However, the incorrect article still remains in cache and can be served to customers until you send a purge request, which you can also do with an HTTP header. Purging informs the cache to stop serving the cached object to client requests and instead retrieve the newer object from origin. This newer object replaces what's in cache and can be served in response to subsequent requests.
Note that this method of purging only works for remote caches you have implemented, like a reverse proxy or CDN. You cannot send purge requests to a user’s local browser cache to force it to purge. If you’re using a CDN, we recommend setting HTTP headers to prevent objects from being cached in the browser in the first place.
Learn more about cache purging with Fastly Academy.
Learn about caching with Fastly CDN