JakeWharton的DiskLruCache - 如何与排球实现? [英] JakeWharton's DiskLruCache - How to Implement with Volley?

查看:175
本文介绍了JakeWharton的DiskLruCache - 如何与排球实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是与这对于排球图像缓存的问题有关。所以,现在我想实现DiskLruCache,但我不知道如何做到这一点。

This is in connection with this question regarding Volley Image caching. So, now I want to implement DiskLruCache, but I am not sure on how to do this.

我下载了从 github上的Jar文件,并把它添加到我的项目。

I downloaded the Jar file from github and added it to my project.

我该怎么办?我怎样才能改变抽射现有code和整合DiskLruCache?

What should I do next? How can I change the existing code of Volley and integrate DiskLruCache?

现有code:

正开始乱射:

queue = Volley.newRequestQueue(getActivity());
imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
    private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(
            10);

    public void putBitmap(String url, Bitmap bitmap) {
        mCache.put(url, bitmap);
    }

    public Bitmap getBitmap(String url) {
        return mCache.get(url);
    }
});

从服务器获取解析响应:

Getting response from server and parsing:

jsArrayRequest = new JsonArrayRequest(url,
        new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                if (Const.DEBUGGING) {
                    Log.d(Const.DEBUG,
                            "Response => " + response.toString());
                    Log.d(Const.DEBUG, "Length = " + response.length());
                }
                parseResponse(response, url);

                setRetrivalSuccess();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (Const.DEBUGGING) {
                    Log.d(Const.DEBUG, "Volley Error");
                    Log.d(Const.DEBUG, "Error = " + error.toString());
                }

                ((MainFragmentActivity) getActivity())
                        .setSupportProgressBarIndeterminateVisibility(false);

            }
        });
queue.add(jsArrayRequest);

我看到的这么几个例子,但我不明白如何与DiskLruCache链接乱射。

I have seen few examples on SO, but I couldn't understand how to link Volley with DiskLruCache.

推荐答案

ImageLoader的需要ImageCache,使用DiskLruCache,你必须有一个包装了它,它实现ImageCache。 VolleyImageCacheExample (推荐的方法是使用基本内存LRU缓存L1高速缓存和磁盘缓存L2)

ImageLoader needs a ImageCache, to use DiskLruCache, you will have to have a wrapper over it which implements ImageCache. VolleyImageCacheExample (Recommended approach is to use basic memory LRU cache as L1 cache and disk cache as L2)

这篇关于JakeWharton的DiskLruCache - 如何与排球实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆