Android : Volley 1.0.19 how to disable request cache?
r0boto opened this issue · 5 comments
Hello,
I'm using volley library:
compile 'com.mcxiaoke.volley:library:1.0.19'
In http helper class i have the following method.
public static JsonRequest createRequest(String responseType, int requestMethod, String scheme,
String url, final String requestParams, final HttpResponseListener listener,
Request.Priority priority) throws UnsupportedEncodingException {
// Start to prepare request URL
Uri.Builder builder = new Uri.Builder();
builder.scheme(scheme).encodedAuthority(url);
// GET REQUESTS - append the params into URL
if (requestMethod == Request.Method.GET && requestParams != null) {
boolean append = appendParamsToUrl(requestParams, builder);
if(!append) return null;
}
url = URLDecoder.decode(builder.build().toString(), Constants.Request.DEFAULT_ENCODING);
// Get response as JSON object
JsonRequest request;
if (responseType.equals(Constants.Request.JSON_OBJECT)) {
// Prepare request and set the Callbacks
request = new CustomJsonObjectRequest(requestMethod, url, requestParams,
priority, responseListener(listener), errorListener(listener), listener);
}else { // Get response as JSON array of objects
// Prepare request and set the Callbacks
request = new CustomJsonArrayRequest(requestMethod, url, requestParams,
priority, responseArrayListener(listener), errorListener(listener), listener);
}
request.setTag(REQUEST_TAG);
request.setShouldCache(false);
return request;
}
When i using the option:
request.setShouldCache(false);
To force disabling cache.
But when i get the response from server from the POSTMAN (Chrome extension for API testing) i got different values in response than on the Android device.
I tried also use the:
queue.getCache().clear();
But with the same results.
How can i force disable the cache from response?
Many thanks for any advice.
Related to:
http://stackoverflow.com/questions/34792156/android-volley-1-0-18-how-to-disable-request-cache
No answers!!
@r0boto did you find answer? please help
i have same issue too.... plz help us
Did you get an answer?
I solved this problem by this way:
RequestQueue queue = Volley.newRequestQueue(context);
queue.getCache().clear();
StringRequest myReq = new StringRequest(Request.Method.POST,
VolleyConnector.url,
createMyReqSuccessListener(),
createMyReqErrorListener()) {
protected Map<String, String> getParams() throws com.android.volley.AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Cn","1");
params.put("Yr","1396");
params.put("MaxInPage","10");
params.put("Method","Control_Vaziat_View");
params.put("Pg","1");
return params;
};
};
myReq.setShouldCache(false);
queue.add(myReq);
hope this code will help you, but am not sure
RequestQueue queue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack()));