How to call cURL without using server-side cache?

LinuxBashCachingCurlMemcached

Linux Problem Overview


Is there a way to tell cURL command not to use server's side cache? e.g; I have this curl command:

curl -v www.example.com

How can I ask curl to send a fresh request to not use the cache?

Note: I am looking for an executable command in the terminal.

Linux Solutions


Solution 1 - Linux

I know this is an older question, but I wanted to post an answer for users with the same question:

curl -H 'Cache-Control: no-cache' http://www.example.com

This curl command servers in its header request to return non-cached data from the web server.

Solution 2 - Linux

The -H 'Cache-Control: no-cache' argument is not guaranteed to work because the remote server or any proxy layers in between can ignore it. If it doesn't work, you can do it the old-fashioned way, by adding a unique querystring parameter. Usually, the servers/proxies will think it's a unique URL and not use the cache.

curl "http://www.example.com?foo123"

You have to use a different querystring value every time, though. Otherwise, the server/proxies will match the cache again. To automatically generate a different querystring parameter every time, you can use date +%s, which will return the seconds since epoch.

curl "http://www.example.com?$(date +%s)"

Solution 3 - Linux

Neither -H 'Pragma: no-cache' nor -H 'Cache-Control: no-cache' helped me. In browser with "cmd+shift+r" (full reload) I was seeing a new version than the output of curl in terminal.

How to debug for yourself

To get the exact same result, I went to browser > F12 (Dev Tools) > Network/Requests > Right-click on the request > "Copy as cURL" and got the equivalent cURL command to the browser's call.

Then, I pasted that in the terminal and started removing the params one by one, until I found that surprisingly --compressed was making a difference in my case. (Calling CloudFront AWS)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontokhiView Question on Stackoverflow
Solution 1 - LinuxstoicbabyView Answer on Stackoverflow
Solution 2 - LinuxwisbuckyView Answer on Stackoverflow
Solution 3 - LinuxAidinView Answer on Stackoverflow