Caching uncertainty

34 views
Skip to first unread message

Ivan Kiliian

unread,
Jul 14, 2014, 6:06:47 AM7/14/14
to volley...@googlegroups.com
Hello! I'm new to Android! And I'd like to use Volley for network requests.
But cannot understand the following.

My app makes GET requests to YouTube and shows results (videos titles and images) in listview.
from tutorials smth like this:

Cache cache = AppController.getInstance().getRequestQueue().getCache();
Entry entry = cache.get(url);
if(entry != null){
//parse json from entry.data
}else{
//new JSONObjectRequest and parse response
}

But what should I do if new video is uploaded to the channel? (video are not added as new listview item)
- don't use cache
- use cache.remove(url) when app is starting
- use cache.invalidate(url, true/false) (how to use?)
- something other

Please give me answer for the best performance.

Ralph Bergmann | the4thFloor.eu

unread,
Jul 14, 2014, 10:59:13 AM7/14/14
to volley...@googlegroups.com
Hi,


Am 14.07.14 12:06, schrieb Ivan Kiliian:
> Cache cache = AppController.getInstance().getRequestQueue().getCache();
> Entry entry = cache.get(url);
> if(entry != null){
> //parse json from entry.data
> }else{
> //new JSONObjectRequest and parse response
> }

The JSONObjectRequest handles the caching stuff. You don't need to call
cache.get(url)

For an example see
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/
step 4

> But what should I do if new video is uploaded to the channel? (video are
> not added as new listview item)
> - don't use cache
> - use cache.remove(url) when app is starting
> - use cache.invalidate(url, true/false) (how to use?)
> - something other

You have to call the JSONObjectRequest again. If the content has changed
the JSONObjectRequest downloads it. If it hasn't changed you get the
cached content.



Ralph

signature.asc
Reply all
Reply to author
Forward
0 new messages