Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - How to retrieve images from cache memory in picasso?

I am using picasso library for loading images .In default picasso, It uses internal cache memory for loading images.But as per my app configuration ,i have to use external cache memory(Cache on Disk). so i used this code for Cache on Disk

              File httpCacheDir = new File(getApplicationContext().getExternalCacheDir(),"http");
                long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
               HttpResponseCache.install(httpCacheDir, httpCacheSize);}

Picasso is flexible. So now it caches images in external Sd card..

The caches is stored in sdcard/android/data/packagename/cache/http The caches are stored in ".1" ,".0". formats so i just opened them and changes into ".1" to ".jpg".it gives exact images what i need. But how to do in programatically? but picasso itself caches my memory in to my app for loading image into imageview.but i have to save them into sdcard directly as images/set bitmap as wallpaper in offline mode?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can supply your own Cache implementation when building your Picasso instance. This way you can provide extra methods that you can call to retrieve bitmaps directly from your memory cache. Use Picasso.Builder to provide your own implementation for it. When you use with() you are using a static singleton internal instance thats setup with most of the default values (most apps need the default values anyway.)

Keep a reference of your Cache implementation around and directly interact with it. Picasso is meant to handle the loading/decoding and caching for you but there is no reason you cant build around it.

If you are referring about the disk cache, then no Picasso does not support that at the moment. This is by design because the disk layer cache is done by the HTTP layer and makes no distinction about it.

You could however, change the path of the disk cache. If you are using OkHttpDownloader then supply a different file when you construct your Downloader. Similarly for UrlConnectionDownloader you could extend it and override the load() method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...