Bypassing Cache for Curl requests

Curl does not cache any requests on the client side; therefore, any caching when using Curl occurs on the server side. To bypass the server-side cache, you can use the Cache-Control HTTP header to control the caching behavior. The HTTP Cache-Control header is only available in HTTP 1.1, and for backward compatibility with systems that are still using HTTP 1.0, you can use the 'Pragma: no-cache' header. Click Run to execute the Curl No Cache Example online and see the result.
Bypassing Cache for Curl requests Run
curl https://reqbin.com/echo
	-H "Cache-Control: no-cache, no-store, must-revalidate"
    -H "Pragma: no-cache"
Updated: Viewed: 9708 times

What is Curl?

The Curl is a command-line tool for transferring data from a client to a server. With Curl, you can upload or download data using HTTP, HTTPS, SCP, SFTP, and FTP protocols. Curl supports bandwidth limiting, proxy support, user authentication, SSL, certificate validation, and HTTP cookies. The Curl runs on all modern platforms, including Windows, Linux, and macOS.

What is a Cache?

The Cache is a temporary storage device in a computing environment, typically used to store data. A cache is a small amount of faster, more expensive memory used to speed up recent or frequently accessed data. Cache data is stored on local media, separate from the main storage accessible to the cache client. Caches are commonly used by the central processing unit (CPU), web browsers, applications, and operating systems. The cache is used because bulk or core storage cannot meet the customers' needs. The cache reduces data access time, reduces latency, and improves input/output (I/O). Since almost all application workloads depend on I/O operations, the caching process improves application performance.

Curl No Cache Example

The following is an example how to use Curl without cache:

Cache-Control HTTP header addition

We can use the Cache-Control HTTP header in both HTTP requests and responses to control the caching behavior. We need to provide directives under this heading and some directives that may be of interest to us:

  • no-cache: the setting will cause the cache to be re-checked with the original resource before sending the response
  • no-store: the parameter specifies that the response to this request should not be cached at all
Curl Cache-Control HTTP Header Example
curl https://reqbin.com/echo
	-H "Cache-Control: no-cache, no-store"

Pragma HTTP header addition

HTTP - Cache-Control header only appeared in HTTP 1.1. For backward compatibility with systems that are still using HTTP 1.0, we can use the Pragma header:

Curl Pragma HTTP Header Example
curl https://reqbin.com/echo
    -H "Pragma: no-cache"

See also

Generate Code Snippets for Curl No Cache Example

Convert your Curl No Cache request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the ReqBin code generator.