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

Embeded image

Create a cache purge job for the sample application

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.

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

Verify the cache status

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

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

Try purging by URL prefixes

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.

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.

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

It is also a cache miss as desired.

screenshot 3

Or the /en/ page itself.

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

Custom purge conditions

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.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

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

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.