1

I use Picasso to load images from server and Volley to do requests.

Example:

Picasso.with(getContext()).load(article.getImagePath()).error(R.drawable.placeholder_blue_sd).placeholder(R.drawable.placeholder_blue_sd).into(image);
  1. How do I get cache size?
  2. How to empty the cache?
ShahiM
  • 3,179
  • 1
  • 33
  • 58
mstafkmx
  • 419
  • 5
  • 17

1 Answers1

0

1. How to get Cache size

Well, you can do that like this :

StatsSnapshot picassoStats = Picasso.with(context).getSnapshot();

The statsSnapshot object contains the following params :

StatsSnapshot{
maxSize=28760941,
size=26567204,
cacheHits=30,
cacheMisses=58,
downloadCount=0,
totalDownloadSize=0,
averageDownloadSize=0,
totalOriginalBitmapSize=118399432,
totalTransformedBitmapSize=96928004,
averageOriginalBitmapSize=2466654,
averageTransformedBitmapSize=2019333,
originalBitmapCount=48,
transformedBitmapCount=41,
timeStamp=1432576918067}

Read more here

2. How to clear cache

There is no direct method (in Picasso) to clear the entire cache because :

Picasso doesn't have a disk cache, the HTTP client is responsible for it. You can install your own disk cache into the HTTP client and delete the contents of the folder to clear it if you want.

Source : Picasso Issue#1543 and Picasso Issue#1521

but if what you want is to force refresh a single image, you can specify NO_CACHE for both memoryPolicy and diskPolicy to skip the cache and force refresh.

Picasso.with(context)
       .load(newUri)
       .memoryPolicy(MemoryPolicy.NO_CACHE)
       .diskPolicy(MemoryPolicy.NO_CACHE)
       .into(imageView);

or

you can just call invalidate on the url

Picasso.with(context).invalidate(uri.toString());
ShahiM
  • 3,179
  • 1
  • 33
  • 58