}
private void _requestCacheInvalidation(int type) throws Exception {
Client client = new CommonsClient();
RequestOptions options = client.getDefaultRequestOptions();
options.setHeader("Connection", "close");
options.setHeader("x-reqnum", "1");
ClientResponse response = client.get(CHECK_CACHE_INVALIDATE, options);
String resp1 = getResponse(response);
assertEquals(resp1, "1");
// Should not use the cache
options.setHeader("x-reqnum", "2");
switch(type) {
case NOCACHE: options.setNoCache(true); break;
case NOSTORE: options.setNoStore(true); break;
case MAXAGE0: options.setMaxAge(0); break;
}
response = client.get(CHECK_CACHE_INVALIDATE, options);
String resp2 = getResponse(response);
assertEquals(resp2, "2");
// Should use the cache
options.setHeader("x-reqnum", "3");
switch(type) {
case NOCACHE: options.setNoCache(false); break;
case NOSTORE: options.setNoStore(false); break;
case MAXAGE0: options.setMaxAge(60); break;
}
response = client.get(CHECK_CACHE_INVALIDATE, options);
String resp3 = getResponse(response);
assertEquals(resp3, "2");