Purge based on URL

Hi,

Here is an example scenario.

Let’s say the path you are searching for includes “my_path_segment” and the surrogate key will be called “my_surrogate_key”.

  1. Create a VCL snippet to select the right pages:

Name: “Set Surrogate-Key”
Type: fetch
Priority: 99
Code:

if ( req.url ~ "^.*/my_path_segment/.*$" ) { 
   set beresp.http.surrogate-key = if (beresp.http.surrogate-key, beresp.http.surrogate-key + " " + "my_surrogate_key", "my_surrogate_key"); 
}

An advantage of priority 99 instead of 100 is so it will be evaluated before 100 which may include return (deliver); statements that short-circuit evaluation.

Run curl locally.

$ curl -X POST -H 'Fastly-Soft-Purge:1' -H 'Fastly-Key: YOUR_FASTLY_TOKEN' -H 'Accept: application/json' https://api.fastly.com/service/<SID>/purge/<S-Key>

An issue I encountered when researching this topic was the curl command was missing on many doc pages when searching for “Fastly Purge”, “Purge based on URL”, and “Surrogate Key”. I eventually found it in a page about “Soft Purges”.

However, when someone is investigating “fastly purge”, the concept of “soft” is not at the top of your mind. The admins might consider propagating the curl commands to a few more of the existing documentation pages even those which aren’t focused specifically on “soft purge”.

Any comments are welcome about the above steps.

1 Like

That’s good feedback on the prominence of Soft Purge in the docs. Are there specific ones you checked early on / are there specific docs where you’d expect to see different content?

Hi Austin,

The information can eventually be found. It’s not entirely missing.

Let’s say the goal is to find the curl command in conjunction with a surrogate key. That’s necessary to purge based on a wildcard URL path. If it shows “curl -X PURGE”, that’s not quite it yet.

google this search, without quotes: “fastly purge surrogate key”
result 1: Purging with surrogate keys NO
result 2: Working with surrogate keys NO
result 3: Purging | Fastly Documentation Initially, NO. Ctrl-F (find curl on page), no result. But it is there! hidden away. You have to click to find it.
result 4: Purging | Fastly Documentation NO
result 5: Surrogate-Key | Fastly Documentation NO
result 6: fastly purge | Fastly Documentation NO
result 7: https://support.globaldots.com/hc/en-us/articles/360019893392-Fastly-how-to-Purge-by-Surrogate-Key NO Some clues though.
result 8: Purging | Fastly Help Guides NO
result 9: Cache Invalidation on Fastly with Surrogate Keys NO
result 10: Use surrogate key purges for purge-all and single URL purge | Fastly Documentation NO

Google this search, without quotes: “fastly purge based on url”.

result 1: Purging | Fastly Help Guides NO. But it leads to:
result 1a: Authenticating URL purge requests via API NO
result 1b: Purging a URL via the web interface NO
result 1c: Purging all content via the web interface NO
result 1d: Purging with surrogate keys NO
result 1e: Soft purges YES. That is where I found it. (But I didn’t want “soft” purge, so that threw me off).
result 1f: Working with surrogate keys NO
result 2: Purging a URL via the web interface NO.
result 3: Purging | Fastly Documentation Initially, NO. Ctrl-F (find curl on page), no result. But it is there! hidden away. You have to click to find it.
result 4: Purging | Fastly Documentation NO
result 5: Purge everything under a URL path prefix | Fastly Documentation NO
result 6: bash - Purge a URL from the Fastly CDN via API call with curl or wget - Stack Overflow NO
result 7: Soft purges YES, this is where I found it.
result 8: PURGE all for given resource NO
result 9: https://www.drupal.org/project/fastly/issues/3438700 NO
result 10: caching - Fastly purges pages for no reason - Stack Overflow NO

If there is any discovery here, it might be:

  • Purging | Fastly Documentation is the page which is meant to show the answer of this query.
  • While being maximally elegant and beautiful, the page may be outsmarting casual users, such as myself.

I wonder if there could be a compromise between displaying all data in that page, and having everything hidden inside drop-down sections that don’t allow Ctrl-F find-on-page. At least worth thinking about.

Going further…

search: ctrl-f find on page trigger expand

javascript - Expanding hidden content when stepping with search on page (ctrl+f) in chrome - Stack Overflow
javascript - How to expand all rows of a html table on Ctrl+F - Stack Overflow
javascript - Expand all collapsible sections for text search - Stack Overflow
javascript - Detect page find/search to expand a collapsible - Stack Overflow
( only a few and not necessarily the correct ones. there are more solutions out there )

This is good feedback, I’ll pass this on to the team. Thanks!