After updating content, wondering why CDN still gives old content ?

Brief about CDN:


Content delivery network - Wikipedia


Content Delivery Network (CDN) - Geographically distributed group of servers, which work together to provide fast delivery of internet content.

CDN helps to minimize the distance between the visitors and your website's server, a CDN stores a cached version of its content in multiple geographical locations also known as point of presence (PoP).

Each PoP contains a number of caching servers responsible for content delivery to visitors within its proximity

Brief about CDN Cache:

By this time, you might have already figured out why CDN still gives old content. Anyway let's continue to get more insights


During setting up your CDN service with any service providers for example: Amazon Cloudfront, you would be given an option to choose its cache behaviour settings

  • Option-1: Use Origin Cache Headers

If your origin server / service is adding a Cache-Control header,  the same would be used by CDN service to decide how long objects stay in the CDN cache

  • Option-2: Customized cache settings

You can define minimum, maximum and default TTL (Time to Live).
According to the cache settings (TTL),  objects stay in CDN caches and CDN service forward another request to your origin to determine whether the object has been updated


Reason:

According to your cache settings, you may have to invalidate the cache
  • Invalidate the cache from your origin server / service side
  • Invalidate the cache at CDN end

CDN Service generally provide option for cache invalidation
Most of the Cache invalidation handled using Path Patterns

Example:

/videos - invalidate cache of all objects under videos path of your service
/* -  all objects whose paths begin with that prefix are invalidated.


Notes:

  • Cache Invalidation mostly intended for use in exceptional circumstances, not as part of normal workflow. 
  • As an alternative to routine invalidations, you can proactively set appropriate expiration times on responses or use different URLs for different versions of the content


References:

https://cloud.google.com/cdn/docs/cache-invalidation-overview
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html



Post a Comment

1 Comments