2

I need to manually add a bitmap to the cache specifying the URI (as key). If the request URI to download the image matches with the key, I need the pipeline to load the bitmap from the cache instead of making the network call.

I found this method Fresco.getImagePipelineFactory().getBitmapMemoryCache().cache( cacheKey, closeableReference). But how to get a closableReference to an arbitrary bitmap. Please help. Thank you.

Chethan N
  • 1,110
  • 1
  • 9
  • 23

2 Answers2

1

If you are loading image with Fresco - yes:

public class OperationPostprocessor extends BasePostprocessor {
  private int myParameter;

  public OperationPostprocessor(int param) {
    myParameter = param;
  }

  public void process(Bitmap bitmap) { 
    doSomething(myParameter);
  }

  public CacheKey getPostprocessorCacheKey() {
    return new MyCacheKey(myParameter);
  }
}

Cache key is MyCacheKey(myParameter)

You can use it when you are forming ImageRequest:

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(photoUri)
                .setPostprocessor(new OperationPostprocessor())
                .build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setOldController(simpleDraweeView.getController())
                .setImageRequest(request)
                .build();
simpleDraweeView.setController(controller);

Here you will use your postprocessor: .setPostprocessor(new OperationPostprocessor())


Resources:


One detail: here will be using fresco cache, but in Postprocessor.process(Bitmap) method, i think, you can add bitmap to your own cache.

Victor Ponomarenko
  • 490
  • 1
  • 7
  • 12
0

I wrote a post explaining observations / experience with Fresco here.

Also check this post at medium

It has the solution to above problem too.

Chethan N
  • 1,110
  • 1
  • 9
  • 23