as Volley.Request.getCacheKey() returns a url which is the same in my case; it did not work for me.
Instead, I had to override getCacheKey () in my child class to return URL + POST (key = Value)
Thus, I was able to cache all POST requests made to the same URL with different POST data.
when you try to get a cached request, you need to build the cache key in the same way.
so here is a snapshot of my code:
public class CustomPostRequest extends Request<String> { . . private Map<String, String> mParams; . . public void SetPostParam(String strParam, String strValue) { mParams.put(strParam, strValue); } @Override public Map<String, String> getParams() { return mParams; } @Override public String getCacheKey() { String temp = super.getCacheKey(); for (Map.Entry<String, String> entry : mParams.entrySet()) temp += entry.getKey() + "=" + entry.getValue(); return temp; } }
When you build a new query, you can use getCacheKey () to search for a cached query first before placing it in the query queue.
Hope this helps.
source share