mcxiaoke / android-volley

DEPRECATED
4.29k stars 1.56k forks source link

Android : Volley 1.0.19 how to disable request cache? #134

Open r0boto opened 8 years ago

r0boto commented 8 years ago

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

basmasrour commented 8 years ago

No answers!! @r0boto did you find answer? please help

majithg commented 8 years ago

i have same issue too.... plz help us

ajaykarthikr commented 7 years ago

Did you get an answer?

S-Masoud-Emamian commented 7 years ago

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);
ashiqmuhammed commented 6 years ago

hope this code will help you, but am not sure RequestQueue queue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack()));