How To Disable Caching for all HTTP Requests in Quarkus

To disable HTTP cache with the following headers:


Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0    
...for all requests add the quarkus-undertow extensions first: mvn quarkus:add-extension -Dextension="quarkus-undertow"

With the added extension, Quarkus understands the "Undertow Predicate Language", which can be used to manipulate the HTTP request and responses. Quarkus expects the configuration file: undertow-handlers.conf to be located in src/main/META-INF (same directory as application.properties).

The built-in Disable Cache Handler with the name disable-cache already sets all the necessary headers. Caching of all GET-requests (JAX-RS, Servlet and static content), can be disabled with the following line in undertow-handlers.conf:


method(GET) -> disable-cache

Now curl -i localhost:8080 generates the following output:


HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
(...)
See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License