0

I add a Perference in my PerferenceFragment.

deleteCache.setOnPreferenceClickListener(preference -> {
        Fresco.getImagePipeline().clearDiskCaches();
        deleteCache.setSummary(String.format(getString(R.string.delete_format), getDiskSize()));
        return true;
    });

public static final long getDiskSize(){
    long bytes = Fresco.getImagePipelineFactory().getMainFileCache().getSize();
    return bytes==-1?0:bytes;
}

I think that I click the perference that getDiskSize() should return 0,but I should click second or more times then the summary show the diskcache is 0 B.I can not find the reason about my solution.

more Info:

  • Fresco 1.1
  • get cache size
  • I use Fresco.getImagePipeline().clearCaches(); it can not slove problem

ImagePipelineConfig

Set<RequestListener> requestListeners = new HashSet<>();
    requestListeners.add(new RequestLoggingListener());
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
            .newBuilder(this, RetrofitHelper.initClient())
            .setBitmapsConfig(Bitmap.Config.RGB_565)
            .setRequestListeners(requestListeners)
            .build();

I click the preference that getDiskSize() fail to return 0 at first time.

ilumer
  • 125
  • 1
  • 11

1 Answers1

0

I read the code find the this is an asynchronous operation .

return Task.call(
      new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          mStagingArea.remove(key);
          mFileCache.remove(key);
          return null;
        }
      },
      mWriteExecutor);
/**
* Represents the result of an asynchronous operation.
* 
* @param <TResult>
*          The type of the result of the task.
*/
public class Task<TResult>
ilumer
  • 125
  • 1
  • 11