Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call cURL without using server-side cache?

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.

like image 576
tokhi Avatar asked Jul 27 '15 12:07

tokhi


People also ask

How do I disable caching in curl?

curl -v -H "Cache-Control: no-cache" That will tell the web server to not cache. Doesn't stop layers below caching unless it's coded to obey the headers.

Why is my curl client caching files?

The curl client isn't caching files, but the remote server network might well be. Try adding an arbitrary query string variable to the URL to see if you can reproduce it.

How does curl communicate with a server?

It communicates with a web or application server by specifying a relevant URL and the data that need to be sent or received. curl is powered by libcurl, a portable client-side URL transfer library.

How do I use curl command in Linux?

The syntax for the curl command is as follows: curl [options] [URL...] Here are the options that we’ll use when making requests: -X, --request - The HTTP method to be used. -i, --include - Include the response headers. -d, --data - The data to be sent.


2 Answers

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.

like image 123
stoicbaby Avatar answered Oct 22 '22 23:10

stoicbaby


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)"
like image 94
wisbucky Avatar answered Oct 23 '22 00:10

wisbucky