How to implement my own disk cache with picasso library - Android?

后端 未结 2 1819
一向
一向 2020-11-27 19:00

I\'m using picasso library to load images for my app. But I don\'t how to implement my own disk (sdcard) caching with picasso library.

2条回答
  •  遥遥无期
    2020-11-27 19:51

    @Dax, to save files in custom cache directory using OkHttp, I would code something like this -

    OkHttpClient okHttpClient = new OkHttpClient();
    File customCacheDirectory = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/MyCache");
    okHttpClient.setCache(new Cache(customCacheDirectory, Integer.MAX_VALUE));
    OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient);
    Picasso picasso = new Picasso.Builder(mainActivity).downloader(okHttpDownloader).build();
    picasso.load(imageURL).into(viewHolder.image);
    

    Hope this helps.

提交回复
热议问题