Fresco agregar mapa de bits a caché programatically
Estoy subiendo una imagen a mi servidor y una vez cargado mi servidor responde con el nuevo URI para él (puede ser la misma URL que la antigua), quiero quitar la vieja imagen en caché e insertar la nueva para el nuevo URI.
Trato de lograr esto haciendo:
// Retrofit2 onResponse String newImageUri = response.body().getUri(); String oldImageUri = Preferences.getUser().getImageUrl(); // Remove old image from cache Fresco.getImagePipeline().evictFromCache(Uri.parse(oldImageUri)); Fresco.getImagePipeline().evictFromDiskCache(Uri.parse(oldImageUri)); Fresco.getImagePipeline().evictFromMemoryCache(Uri.parse(oldImageUri)); Fresco.getImagePipelineFactory().getMainFileCache().remove(new SimpleCacheKey(oldImageUri)); // Insert new image at new URI try { Fresco.getImagePipelineFactory().getMainFileCache().insert(new SimpleCacheKey(newImageUri), new WriterCallback() { @Override public void write(OutputStream os) throws IOException { os.write(imageData); // byte[] or the new Bitmap } }); } catch (Exception e) { e.printStackTrace(); } uriProfileImage.setImageURI(newImageUri);
No hay excepciones, pero todavía sólo veo la vieja imagen.
Lo resolví, fue un error con el formato Uri para el nuevo Uri …
Uri uri = Uri.parse("http://frescolib.org/static/fresco-logo.png"); Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new CacheKey(uri.toString())); Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new CacheKey(uri.toString()));