Caching in Picasso

雨燕双飞 提交于 2019-12-13 21:07:58

问题


After reading several documentations, i want to clear some points

Reference: this

  1. For Picasso to cache my image into memory, do i have to enable "Cache-control" header in my response?

  2. If i am using OkHttpDownloader with Picasso,will it still require me to enable the header?

    public Picasso getImageLoader(Context ctx) {
    
    Picasso.Builder builder = new Picasso.Builder(ctx);
    
    builder.downloader(new OkHttpDownloader(ctx) {
        @Override
        protected HttpURLConnection openConnection(Uri uri) throws IOException {
            HttpURLConnection connection = super.openConnection(uri);
    
            connection.setRequestProperty("X-User",user.getUsername());
            connection.setRequestProperty("X-Token",user.getToken());
    
            return connection;
        }
    });
    return builder.build();
    }
    

3 Does disk caching work in Picasso on Android 4.3 or lower. Will it load my image from disk if the net is disconnected?


回答1:


In Picasso Caching is enabled by default.

and other settings you can do by this function memoryPolicy(,)

Picasso  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[1])
    .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageViewFromDisk);


来源:https://stackoverflow.com/questions/25058531/caching-in-picasso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!