Today I’d like to show how to purge OpenResty Edge’s HTTP cache across the whole gateway network in real time.

Embeded image

As always, let’s go to the OpenResty Edge’s Admin web console. This is our sample deployment of the console. Every user has her own local deployment.

Screenshot

This time we use a real world application for our openresty.org website.

Screenshot

Enter this application.

Screenshot

Go to the Cache Purge page of this application.

Screenshot

We can see that we already have a lot of previous purge jobs.

Screenshot

Let’s create a new purge job.

Screenshot

We can see that we can purge either by full URLs,

Screenshot

URL prefixes,

Screenshot

or complex custom conditions.

Screenshot

We’d try the full URL mode first.

Screenshot

This is the FAQ page on that site. Note that it does not matter if we use http:// or https:// here. This is because we did not include the scheme string in our cache key. The scheme string is not included by default.

Before submitting the purge job, let’s make sure the cache is a hit for this web page so that we can test the effect of purges.

Embeded image

On the terminal, we can send test requests to the FAQ web page to make sure it is already a cache hit.

1
curl -I https://openresty.org/en/faq.html

And do it again.

Note the Cache-Status: HIT response header returned.

screenshot 2

Then submit our cache purge job.

Screenshot

Great! It is already purged across the whole network.

Screenshot

Unlike the rest of the application-level configurations, cache purge jobs are synchronized across the gateway network immediately. It does not require making new application configuration releases.

Cache purges do not require server reload, restart, or binary upgrade.

Embeded image

Let’s verify the cache status again on the terminal.

1
curl -I https://openresty.org/en/faq.html

Note the Cache-Status: EXPIRED response header returned. It is indeed a cache miss now.

screenshot 1

The second request should be a cache hit again.

Note the Cache-Status: HIT response header.

screenshot 3

Let’s try purging by URL prefixes this time.

Screenshot

We purge everything under the /en/ location.

Screenshot

Now submit the new job.

Screenshot

It has been propagaged to the whole gateway network now.

Screenshot

Send the test request to our FAQ page.

1
curl -I https://openresty.org/en/faq.html

It is indeed a cache miss as expected.

screenshot 1

Test another page under the /en/ URI prefix, the events page.

1
curl -I https://openresty.org/en/events.html

It is also a cache miss as desired.

screenshot 3

Or the /en/ page itself.

1
curl -I https://openresty.org/en/

Also a cache miss.

screenshot 5

We can also purge other kinds of resources like all CSS files, all our images, as long as these files are grouped under pre-defined URL locations.

Screenshot

We don’t bother actually submitting this new purge job.

Screenshot

We may want to define more complicated purge conditions.

Screenshot

We could, for instance, purge all resources with the URI suffix .css, no matter what their URI locations are.

Choose the suffix match operator.

Screenshot

Screenshot And then enter the suffix string value.

Screenshot

We can add more conditions to the current purge job which are AND’d together.

Screenshot

We may add a condition checking URI arguments, request headers, cookies, and many more.

Screenshot

We may also use wildcard or regular expression patterns instead of a literal string pattern.

Screenshot

Or add more value patterns which are OR’d together.

Screenshot

Screenshot

Feel free to try these conditions yourself. As we can see, it is very flexible, just like our Page Rules’ conditions. This is what I’d like to cover today.

If you like this tutorial, please subscribe to this blog site and/or our Vimeo account and/or our YouTube channel. Thank you!

About This Article and Associated Video

This article and its associated video are both generated automatically from a simple screenplay file.

About The Author

Yichun Zhang is the creator of the OpenResty® open source project. He is also the founder and CEO of the OpenResty Inc. company. He contributed a dozen open source Nginx 3rd-party modules, quite some Nginx and LuaJIT core patches, and designed products like OpenResty XRay and OpenResty Edge.

Translations

We provide the Chinese translation for this article on blog.openresty.com.cn. We welcome interested readers to contribute translations in other natural languages as long as the full article is translated without any omissions. We thank them in advance.

We are hiring

We always welcome talented and enthusiastic engineers to join our team at OpenResty Inc. to explore various open source software’s internals and build powerful analyzers and visualizers for real world applications built atop the open source software. If you are interested, please send your resume to talents@openresty.com . Thank you!