# Fastly Cache

The Fastly cache is fast. I love the fact they use Varnish, because I like to use Varnish for some of my own projects. Fastly may charge a bit more for bandwidth than other CDNs, but it is worth it.

### Instant Purge

Once you purge content using their web interface or API, it is done within 150 milliseconds. They focus their infrastructure in the same datacenters as major internet exchange points, which are also the locations of the same major cloud providers. Since most of us use a major cloud provider, the distance traveled from the origin to Varnish is usually pretty small. So, after purging, your cache can be refreshed quickly.

### Surrogate Key

I have multiple sites configured on one service, so purging all the cache wouldn’t be smart since I may only need to clear the cache for one site. This is where their surrogate keys come in handy. Setting your own key is very handy, and you can configure the service to automatically add a key with the domain name to all requests to that site. This allows you to easily purge all the cache with the “levi.lol” tag.

Here is how you can use your domain as a surrogate key.

set req.http.Surrogate-Key = req.http.host;

Or reference the instructions on Setting Surrogate-Key headers based on a URL. Except, change Type/Action to Request and Source to req.http.host. Now you can purge all the content for one domain. This is handy if you’re using one service for multiple sites.

### Soft Purge

This allows your site to remain performant even after purging the cache. It waits until there is a request for that asset to get an updated version. It will serve the stale content once, then replace it with the new version. This helps with the delay of retrieving new content from the origin.