I am having an issue in the app which I think it may be connected to Volley pulling data from the cache.
Namely, the app is heavily bound to the API so each change is being sent to the API and then later retrieved from the API using the Volley library. So a user will open a popup, chose some group to see its items then select some value to mark it favorite. The popup will close and the fragment will reload with new data.
When a user opens the popup again, selects the same group to load its data, the previously item will not be shown as favorite. But when a user touched the same group once more to reload its data, the item WILL BE shown as favorite.
I have debugged the code step by step and I found no error. So I concluded that Volley may be pulling data from its cache, while initiating a new API request the 2nd time I click on the group.
I would like to test if it's a cache issue or I have to debug deeper.
Is there a way to tell Volley NOT to use cached request data, but to initiate the new request to API? Something like don't use cached data, but make a new request
.
NOTE: I would not like to delete the complete cache. I'd only like to tell Volley when to initiate a brand new request to the API.
IMO, if your project uses Google's volley as a module (not jar file), you can customize its classes like the following:
OPTION #1:
First file, RequestQueue.java:
add a class variable
private boolean mCacheUsed = true;
and the following constructors:
then, inside
public <T> Request<T> add(Request<T> request) {
, you check as the following:Second file, Volley.java:
Finally, in MainActivity, for example:
If want to use available cache:
If don't want to use available cache:
OPTION #2:
Request.java:
Add a class variable
public boolean mSkipAvailableCache = false;
RequestQueue.java:
inside
public <T> Request<T> add(Request<T> request)
, you check as the following:MainActivity.java: You can set
available cache will not be used. Hope this helps!
Even i had the same problem before, but you can change it using this