I am using the Fresco library.
I can't find any related info in the Fresco documentation, how can I get an image file from Fresco's disk cache?
I am using the Fresco library.
I can't find any related info in the Fresco documentation, how can I get an image file from Fresco's disk cache?
if the image have download in cache,you can do it like:
ImageRequest imageRequest=ImageRequest.fromUri(url);
CacheKey cacheKey=DefaultCacheKeyFactory.getInstance()
.getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance()
.getMainDiskStorageCache().getResource(cacheKey);
File file=((FileBinaryResource)resource).getFile();
I hope this helps
Check Plamenkos answer on this link.. https://github.com/facebook/fresco/issues/80
if you ask pipeline for an encoded image, and specify DISK_CACHE with ImageRequestBuilder.setLowestPermittedRequestLevel, the pipeline will return you the JPEG bytes if the image is found anywhere up to disk cache, or null if the image is not found and a full-fetch would have to be performed.
I hope I did not mis-understand your question and provide a wrong answer.
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(YourImageUrl))
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
.setResizeOptions(new ResizeOptions(width, width))
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setOldController(YourImageView.getController())
.setImageRequest(request)
.build();
This code:
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
will make fresco get your image from the disk first and then the net.
I think you should never try to get Fresco Cache name cause cache is the internal implement.
But if you want to know whether a image has been cached, you can use this:
private boolean isDownloaded(Uri loadUri) {
if (loadUri == null) {
return false;
}
ImageRequest imageRequest = ImageRequest.fromUri(loadUri);
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
.getEncodedCacheKey(imageRequest);
return ImagePipelineFactory.getInstance()
.getMainDiskStorageCache().hasKey(cacheKey);
}
this method is return very fast, you can use it in UI thread.