Returns a response that clients may cache for the given number of seconds
GET
https://api.testingapis.com/api/cache/max-age/{seconds}Sets Cache-Control: public, max-age=N and Expires. A caching client reuses the same generatedAt until it expires.
Parameters 1
| Name | Type | Description |
|---|---|---|
secondsrequired | path · integer (int32) | Cache lifetime, clamped to 0-31536000 (one year). |
Responses
- 200
- Body with the generation timestamp.
Example
Request
curl -X GET "https://api.testingapis.com/api/cache/max-age/60"Response200 OK
Cache-Control: public, max-age=60
{
"maxAge": 60,
"generatedAt": "2026-09-30T18:26:36.883Z",
"hint": "A caching client should reuse this response (same generatedAt) until it expires."
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/cache/max-age/60");
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"GET",
"https://api.testingapis.com/api/cache/max-age/60",
allow_redirects=False,
)
print(response.status_code, response.text)Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.testingapis.com/api/cache/max-age/60"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}