Google Volley - when to use Cache.remove and Cache.invalidate
Asked Answered
F

1

12

I am integrating Volley into a project and came across the standard

[We have items in the Cache, but want to allow the User to refresh anyway] Scenario

Now Google Volley provides 2 ways to clear an item from the Cache:

getRequestQueue().getCache().remove(key);

and

getRequestQueue().getCache().invalidate(key, fullExpire);

I looked into the code and was a bit surprised, that invalidate with fullExpire set to true doesn't behave exactly like a call to remove(key).

Can somebody explain the benefits of using fullExpire over remove()?

Fictile answered 21/6, 2013 at 8:7 Comment(0)
C
15

Remove means you are removing the actual cached data.

Invalidate means you are just marking the data as invalid. So volley will check with the server whether the data is still valid. The full expire determines whether to use the data before volley has validated it with the server.

More details in the source: https://android.googlesource.com/platform/frameworks/volley/+/master/src/main/java/com/android/volley/Cache.java

Callery answered 15/7, 2013 at 6:29 Comment(2)
Thanks .. edited answer to point to correct link. They changed the code structure to use the Studio conventionCallery
Hi , i have used volley caching with pagination when the end of recyclerview is reached it fetches newList from the server which is added to the end of my oldList , if i enable caching then the oldList is again show thus repeating the same list again , so i need to remove cache data onLoadMoreItems() which is called at the end of the recyclerView , how can i achieve this ?Hoard

© 2022 - 2024 — McMap. All rights reserved.