How to call cURL without using server-side cache?
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.
Is there a way to tell curl to not use cache
You can use CURLOPT_FRESH_CONNECT
for this. From curl_setopt
CURLOPT_FRESH_CONNECT TRUE to force the use of a new connection instead of a cached one.
curl_setopt($curl1, CURLOPT_FRESH_CONNECT, TRUE);
According to RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching and 5.2. Cache-Control
The "Cache-Control" header field is used to specify directives for
caches along the request/response chain.
5.2.1. Request Cache-Control Directives defines several directives to control the use of caches for a response. One of these is
5.2.1.4. no-cache
The "no-cache" request directive indicates that a cache MUST NOT use
a stored response to satisfy the request without successful
validation on the origin server.
So setting an appropriate header with
curl_setopt($curl1, CURLOPT_HTTPHEADER, array("Cache-Control: no-cache"));
should ensure, that a valid and up to date response will be returned. I understand, that this may still result in a cached response, if the validation on the server allows to do so.
However, 5.2.2.1. must-revalidate is a Response Cache-Control Directive given by a server together with the response to a request
[...]
The must-revalidate directive ought to be used by servers if and only
if failure to validate a request on the representation could result
in incorrect operation, such as a silently unexecuted financial
transaction.
Related Topics
How to Copy All PDF Files from a Directory and Its Subdirectories to One Location
Issue While Validating Bash Script
Check Free Disk Space for Current Partition in Bash
Difference Between Unix Domain Stream and Datagram Sockets
How to Convert an Ssl Certificate in Linux
How to Execute a Series of Commands in a Bash Subshell as Another User Using Sudo
Linux Command to Check New Files in File System
Linux Loopback Performance with Tcp_Nodelay Enabled
How to Configure Curl to Only Show Percentage
Escape Single Quotes in Shell Script
How to Setup the Passwords-Less Authentication Between Two Different Accounts
Excluding Directory When Creating a .Tar.Gz File
Preserve Colouring After Piping Grep to Grep
How to Make Vim Play Typewriter Sound When I Write a Letter