Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

android - Google Volley - when to use Cache.remove and Cache.invalidate

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()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...