I was wondering if there was a way to replace a image in Fresco without reloading it from the server. I have a app where I let the users modify a image and then I upload that new image to the server. However with the way Fresco works I'd need to upload the new image, remove the current one from the cache, then use the new url to retrieve it from the server where it will then be stored in the cache. I can't seem to find a way to just insert the image into the cache using just the url and bitmap as the key and value (if its even possible).
Asked
Active
Viewed 710 times
2 Answers
1
Fresco currently doesn't support this out of the box, but you could try something like this:
// remove the image from the caches (both disk and memory)
CacheKey diskCacheKey = new SimpleCacheKey(uri.toString());
Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(diskCacheKey);
Fresco.getImagePipeline().evictFromMemoryCache(uri);
// fill the disk cache (note, memory cache will be filled automatically)
Supplier<FileInputStream> inputStreamSupplier = new Supplier<FileInputStream>() {
@Override
public FileInputStream get() {
return new FileInputStream(path);
}
};
EncodedImage encodedImage = new EncodedImage(inputStreamSupplier);
Fresco.getImagePipelineFactory().getMainBufferedDiskCache().put(diskCacheKey, encodedImage);
// re-set the image to the view
mSimpleDraweeView.setImageUri(uri);

plamenko
- 1,068
- 1
- 8
- 10
-
Fresco.getImagePipelineFactory().getMainBufferedDiskCache().put(diskCacheKey, encodedImage); has private access in fresco... I could try forking it and making it public – Papajohn000 Jul 15 '15 at 14:17
0
first:
mSimpleDraweeView.setImageUri(null)
to remove cache
and second:
mSimpleDraweeView.getHierarchy().setPlaceholderImage(drawable);
to place a drawable to show the local image;

Juude
- 1,207
- 2
- 13
- 22