I am using Picasso to save a collection of pictures for offline viewing. Later I need to remove some pictures manually from the cache. I can delete all files from folder, but I don't need this. I need to delete 2 or 3 files from the cache. invalidate doesn't work for me. Can anyone help me?
You can clear in-memory cache in Picasso only per image:
Picasso.with(context).invalidate(imagePath);
Removing all cache is somewhat tricky and described here.
File cache is delegated to HTTP Client, so it's not possible to clear it from Picasso. For more information refer this answer.
Related
I have a scenario where i have to keep few images in offline mode. Now i am confused here that should i rely on Glide's cache or I have to put those images in Internal Storage?
Hopefully Glide will work, but need to know if there exists any limitation if i go with Glide. Here word cache is causing confusion.
Here is the information about underlying memory usage by Glide.
Glide uses DiskLruCacheWrapper as the default DiskCache. DiskLruCacheWrapper is a fixed size disk cache with LRU eviction. The default disk cache size is 250 MB and is placed in a specific directory in the Application’s cache folder.
Further underlying complexities of Glide are here. Hope confusion about the max memory Glide uses is cleared here and if customization is needed, that can also be achieved by following the link mentioned.
I got a question about android fresco library. Do you guys know how to get callback when file is saved in cache? Generally, we could get file from cache:
ImageRequest imageRequest= ImageRequest.fromUri(url);
CacheKey cacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file=((FileBinaryResource)resource).getFile();
However, if I put this in onCreate() function, it will crash since the file was not in the cache yet. Do you guys know how I got get a callback when the fresco finish saving it? Is it DataSubscriber? Could you guys provide an example? I read the documentation but I couldn't figure out.
Thanks.
I am part of the Fresco team and may be able to help. Please see our documentation on how to properly get the encoded image bytes. There is a code example of how to get an InputStream of the encoded image (which is what is being stored in cache). You can then use those bytes directly, or if you need a File in order to pass it somewhere else, you should create your own file and store the returned bytes in it. There is no other safe way to deal with cached images because you have no guarantees that Fresco will not evict (delete) the cached file at any time.
When I use RecyclerView and/or Picasso.
It seems to cache and store alot of data in my application.
However, I want to delete the stored data and the cache in a simple way whenever I am exiting my app.
What is the simplest way to delete all data stored in your created app programmatically?
What is the latest or the efficient way to tell Picasso to not store or cache images?
Picasso has evictAll() API to clear cache. Also you can set Picasso disk cache size to something small or zero.
I am using the Picasso library on my Android app to load images. I would like to add an option called "Clear images cache" on my app that would remove all the downloaded images from the cache, but obviously that would remove the downloaded images from my app only (I mean not from the other apps).
Is there a simple way to do that using Picasso? Using a native component?
Thanks!
You can clear in-memory cache in Picasso only per image:
Picasso.with(context).invalidate(imagePath);
Removing all cache is somewhat tricky and described here.
File cache is delegated to HTTP Client, so it's not possible to clear it from Picasso. For more information refer this answer.
Try this line of code given below, this removes the resource inside ImageView.
Picasso.with(context).setImageResource(0);
I need to download image url and store it in cache as bitmap.My qus is is there any config that i have to do inorder to store the image bitmaps in cache..? Is there any need to create any cache file?
You should try this librairy : https://github.com/square/pollexor
Well, you just can put it in the app's cache (context.getCacheDir()). What I'd recommend is to use wasp: a cool Android library to handle Bitmaps safely (safe == avoid OutOfMemory exceptions which are pretty common), based on a LRU cache.
It also allows you to download images in the background and get a callback once your image is downloaded... or automatically set the image to an ImageView once it gets downloaded. It is open-source, and is available for Maven users too.
Disclaimer: I'm one of the developers working on wasp library.
Depending on how many images you want to cache, you can probably get away with an in-memory cache using a LruCache. I'd cache the downloaded byte array, not the Bitmap, because Bitmaps are Big Things and decoding byte array -> Bitmap is pretty fast.