I’m curious how cache-control directives affect caching, so I made a small experiment to see the interaction between browser, reverse proxy and server.
First of all, I introduced 6 APIs that respond different cache-control value in response header and current time only.
| Reponse Cache-Control | |
|---|---|
| [GET]/cache/get-public | public,max-age=120 |
| [GET]/cache/get-private | private,max-age=120 |
| [GET]/cache/get-unset | max-age=120 |
| [DELETE]/cache/delete-public | public,max-age=120 |
| [DELETE]/cache/delete-private | private,max-age=120 |
| [DELETE]/cache/delete-unset | max-age=120 |
Then I created a simple web page for test
By clicking the buttons, APIs were called and showed the response data on page. Meanwhile, I monitored the developer tool and record the results.
The results of browsers reaction. (on safari, chrome and edge)
- (v) : cached
- (X) : none-cached
| Http Method \ Cache Directive | Public | Private | Unset |
|---|---|---|---|
| GET | V | V | V |
| DELETE | X | X | X |
The results of reverse proxy reaction.
| Http Method \ Cache Directive | Public | Private | Unset |
|---|---|---|---|
| GET | V | X | X |
| DELETE | X | X | X |
According to the results, we know that the browsers would not break the rule of cacheable, and reverse proxy may not store the response when you don’t set public/private directives.